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\$
0

1 Answer 1

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;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .