Convert x y axis velocity to angle and speed
Hello, I wonder if is there a way to convert the x and y force to speed and angle. By looking at my code you could say that the longer you hold the button, the futher the object would jump from its starting position. I want to make the code work the same but using angle and velocity. If you have other ways around or ideas that would be also good.
void Update () {
if (Input.GetMouseButton(0) && player_rb.velocity.y == 0)
{
onGround = true;
jumpup += upwardMultiplier * Time.deltaTime * 2.1f;
jumpside += sidewardMultiplier * Time.deltaTime * 2f;
if (jumpup >= 15.0f)
{
onGround = true;
Jump();
}
}
}
void Jump()
{
if (onGround)
{
player_rb.velocity = new Vector2(jumpside, jumpup);
jumpup = jumpside = 0;
onGround = false;
}
}
Answer by MT369MT · Aug 15, 2018 at 03:58 PM
Hi, to convert a Vector to a Speed and Angle you could use this:
Speed = VelocityVector.magnitude;
Angle = Vector2.Angle(Vector2.right, VelocityVector);
Your answer
Follow this Question
Related Questions
How to jump using a specific force/velocity on y? 0 Answers
Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers
[2D] Velocity increases faster after large force is applied. 0 Answers
Why is my momentum not carrying over to the X axis? 0 Answers
Applied physics force from animations. 0 Answers