velocity and direction problem

i wan’t to have a constant (same) velocity for one object, but when it spawns i want it to go in a random direction how do i do that? [import]uid: 9520 topic_id: 20811 reply_id: 320811[/import]

Use math.random. If you provide code I may be able to explain how to implement this :slight_smile: [import]uid: 52491 topic_id: 20811 reply_id: 82151[/import]

I’m not sure how you would implement this in code but basically what you need to do is the following:

You need to make sure the program picks (v_x,v_y) values so that v is always the same number. So say v=30, then equation number 1 must have v_x v_y values so that v is always 30. These numbers can be both positive and negative because of the v_x^2.

So you want to generate random v_x,v_y for the angle of rotation in equation (2), but these numbers must be such that equation (1) is always satisfied.

v = squareroot(v_x^2+v_y^2) (1)
theta = arctan(v_x/v_y) (2)

Also, as Peach said, math.random() must be used somewhere. [import]uid: 116225 topic_id: 20811 reply_id: 82371[/import]