- Home /
[2D] Object at X distance to Y direction from point
I am making a 2D player out of multiple sprites. One of them is hand which isn't attached to the body and is only hovering. I want this hand to be at specific distance away from the torso all the time and rotating towards mouse.
So known info are:
Start point x1,y1 (player torso position)
Length a (Distance between player torso and hand)
Angle alpha (I have already calculated this with mouse position)
I just don't know how to calculate the end point (player hand position). I have tried using the formula:
x2 = x1 + cos(alpha) * length
y2 = y1 + sin(alpha) * length
but it doesn't work perfectly. The hand is rotating very fast around the torso even with small cursor movement. Like one round per 6 degrees of angle change.
What am I doing wrong? Picture to demonstrate the situation.
EDIT: Solved - Only had to convert degrees to radians!
Answer by stevethorne · Mar 11, 2014 at 04:40 PM
That alpha angle needs to be in radians, are you using degrees?
Oh dear, that was exactly it! Now I feel extremely stupid. Thank you, I have been stuck with this issue for hours now even though it was only a converting issue...
Your answer
Follow this Question
Related Questions
Incorrect usage of Vector3.Dot? 0 Answers
Hop from transform to transform in 2D game? 0 Answers
How do I transform the position of my cube AWAY from the larger cube its attached to? 0 Answers
2d game sprite frame of object issue 1 Answer
2D how to make a sprite follow the mouse position #c 2 Answers