Tuesday, 24 March 2015

Throwing items

One problem need to solve is how objects are thrown. Since I want to use a mouse to aim rather than throwing in the players direction I need to learn how to get the position of the mouse. This is my basic plan of action:

1. Get both the positions of the player and the mouse when clicked (let's say these coordinates are playerX, playerY, clickX and clickY.

2. Find the distance between the player and the cursor:

clickX - playerX = x (adjacent)
clickY - playerY = y (opposite)

distance between player and cursor = z (hypotenuse)

z = (x^2 + y^2)

Now that we have the distance, we can find the angle between the player and the cursor.

3. Getting the Angle:

Use SohCahToa:

Ø = Cos(x/z)

4. Instantiate the object at player, apply force at angle Ø.

Now this may not be the most concise way to solve this problem, but I can always come back to these problems after I've finished and figure out ways in making them simpler.

No comments:

Post a Comment