0
\$\begingroup\$

I want to move an object with a certain angle and speed, is there a was to set this as an initial velocity so that it is still possible for the object to collide and bounce of other objects using its rigid body?

\$\endgroup\$
1
\$\begingroup\$

Figured it out, here is the code that i made:

float angle, speed;
Vector2 newVelocity;

//use sin and cos to work out x and y speed
velocity.x = Mathf.Cos(angle) / speed;
velocity.y = Mathf.Sin(angle) / speed;

//apply the new velocity to the current object
this.GetComponent<Rigidbody2D>().velocity = newVelocity;
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.