Moving variables along an angle.

Get help using Construct 2

Post » Wed May 29, 2013 7:22 pm

I know how to move a sprite along an angle, but I want to move some variables (X & Y) along an angle and distance that I already know (the angle between the player and the mouse cursor). So basically I want to know the math function to update the X and Y position of my sprite with an angle/distance without actually moving the sprite.

I understand that I could move the sprite, update the values, then move the sprite back, or similar tricks. But I want to know the actual mathematical solution (trig functions I think?).
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Wed May 29, 2013 10:36 pm

[code]
x = x + distance * cos(angle)
y = y + distance * sin(angle)
[/code]
---

http://www.mathsisfun.com/sine-cosine-tangent.html



- (x,y) the starting position, is the left-most point of the triangle
- you know the hypotenuse - that's the distance you want to travel
- you know the angle ?

- you want to find the length of the adjacent side which is the how far you need to travel in the x direction
- and the length of the opposite side which is how far to travel in the y direction

[code]
Sine Function: sin(?) = Opposite / Hypotenuse
Cosine Function: cos(?) = Adjacent / Hypotenuse
[/code]

Sine Function (to find Opposite side):
=> sin(?) = Opposite / Hypotenuse
=> Opposite = Hypotenuse * sin(?)
=> y amount = distance * sin(angle)

Cosine Function (to find Adjacent side):
=> cos(?) = Adjacent / Hypotenuse
=> Adjacent = Hypotenuse * cos(?)
=> x amount = distance * cos(angle)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,610

Post » Thu May 30, 2013 12:24 am

Thanks, think I'll bookmark this thread so I can refer back to it next time this crops up :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: angryvel760, Beasthemu8, chrislechat, eryson27, ismael123, LightningFury and 1 guest