Question by
ndrummer31 · Dec 05, 2015 at 06:04 PM ·
mathfmathf.sinmathf.cos
Unit Circle Coordinates
Hello, I've just recently learned the unit circle in school and to help myself further understand it, I thought I'd add it to my movement script so that no matter what direction you're moving, you're going the same speed. There are probably other ways to do this but this was just for a learning experience. Here is my code:
Vector2 desiredInput = Vector2.zero;
desiredInput.x = Mathf.Cos ( Mathf.Atan2 ( rawInput.y, rawInput.x ) * Mathf.Rad2Deg );
desiredInput.y = Mathf.Sin ( Mathf.Atan2 ( rawInput.y, rawInput.x ) * Mathf.Rad2Deg );
float lerpSpeedX = rawInput.x != 0 ? moveSpeedLerpSens : moveSpeedLerpGrav;
float lerpSpeedY = rawInput.y != 0 ? moveSpeedLerpSens : moveSpeedLerpGrav;
input.x = Mathf.Lerp ( input.x, desiredInput.x, Time.deltaTime * lerpSpeedX );
input.y = Mathf.Lerp ( input.y, desiredInput.y, Time.deltaTime * lerpSpeedY );
What about this is wrong? Any help and/or tips would be appreciated!
Comment
Your answer
Follow this Question
Related Questions
Mathf.Approximately, how to apply this to my script? 1 Answer
Save object position after drag? 0 Answers
Problems with instantiated objects in a circle formation 0 Answers
Mathf.Round ? [C#] 2 Answers