- Home /
Weird angle returned
I wrote a script so that the character can dash in the direction of where the mouse is. The problem is that the angle is completely wrong.
Here's the important part of the code:
MouseAngleVec = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
DiffVec = new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.y) - MouseAngleVec;
DiffVec = DiffVec.normalized;
RB.AddForce(DiffVec * DashSpeed, ForceMode2D.Impulse);
Answer by iJuan · May 12, 2018 at 05:38 PM
What you are looking for is Mouse Position - Player Transform (invert their order).
Also, I think that you should transform mouse position from camera space to world space, not really sure about that one (Camera.main.CameraToWorldSpace, or something similar to that)
Thank you for the help, eventually I (somehow) got the code working using ScreenToWorldPoint.
Your answer
Follow this Question
Related Questions
8 Directional sprite in 3d world, how to retrieve direction? 2 Answers
how to get a correct rotation 2 Answers
How to calculate direction between 2 objects 2 Answers
How to get the direction of the velocity of an object (c#) 1 Answer
Projectile Directionality in an isometric view (2D, vector2) 2 Answers