- Home /
get velocity form angle?
I am going to make a 2D game. I want to input angle and speed in the inspector. Then the ammo spawner can shoot the ammo in specific velocity. But I how can I set the ammo's velocity? For example, I input 30° and speed 100, and ammo will be shoot with 30° and 300 speed.
Answer by tormentoarmagedoom · Aug 30, 2018 at 09:32 AM
Good day.
How you will move the bullet? With rigidbody and addforce? or maybe by changing its transform.position?
Anyway, once you have a vector, you can change its magnitude if you reduce that vector to magnitude 1 (with Vector3.normalized) and then multiply this vector for a number.
Something like this:
Vector3 MyNewVector = new Vector3(10, -12, 20);
MyNewVector = MyNewVector.normalized;
MyNewVector = MyNewVector * 5;
//So now i have a vector with lenght (magnitude) 5 in the same direction as the vector (10, -12, 20)
This is how you can easy control direction and magnitude of a vector
Bye!
But how can I transform angle to $$anonymous$$yNewVector(Velocity)? If I set my ammo rigibody2D's velocity= new Vector3(0,0,30).normalized * speed, the ammo still doesn't shoot toward 30°
Your answer
Follow this Question
Related Questions
Converting vector3 velocity to an angel 2 Answers
Velocity to 2D rotation (angle from velocity vector with atan2) 1 Answer
Laser redirected through portal 2 Answers
Average of Normals 1 Answer
Calculate position of camera with set distance and angle. 2 Answers