Velocity question

I wanna shoot a character in a direction (0-360 degrees) at a speed. I know you can use setLinearVelocity but it isn’t quite what I am looking for. Any ideas?

You can use object:applyForce()

https://docs.coronalabs.com/api/type/Body/applyForce.html

–SonicX278

To calculate the velocity for a given direction you will need to start with a point, let’s say {x=10,y=0}, and rotate it to the desired angle. That would give you a velocity of 10 in that direction.

The only way to specify the velocity is to set the velocity. If you use applyForce it will apply a given force in a given direction but it won’t let you set the velocity.

Your question is fairly vague. If that’s deliberate that’s ok, but can you be more specific about what you’re looking for? Maybe provide examples?

you just need to calculate vx and vy for setLinearVelocity(x,y)

velocity = 10

vy = velocity * sin(angle)

vx = velocity * cos(angle)

this will calculate x and y component of velocity and it can be used in function.

NOTICE:

* angle can be i degrees or radians ( rad = 2*3.14/360 * degrees )

* angle 0 i 12 o’clock, angle 90 is 3 o’clock  BUT screen Y is upside down so 0 is 6 o’clock and 90 is 9 o’clock

Hello, yes that makes sense… But he didnt want to setLinearVelocity…

–SonicX278

You can use object:applyForce()

https://docs.coronalabs.com/api/type/Body/applyForce.html

–SonicX278

To calculate the velocity for a given direction you will need to start with a point, let’s say {x=10,y=0}, and rotate it to the desired angle. That would give you a velocity of 10 in that direction.

The only way to specify the velocity is to set the velocity. If you use applyForce it will apply a given force in a given direction but it won’t let you set the velocity.

Your question is fairly vague. If that’s deliberate that’s ok, but can you be more specific about what you’re looking for? Maybe provide examples?

you just need to calculate vx and vy for setLinearVelocity(x,y)

velocity = 10

vy = velocity * sin(angle)

vx = velocity * cos(angle)

this will calculate x and y component of velocity and it can be used in function.

NOTICE:

* angle can be i degrees or radians ( rad = 2*3.14/360 * degrees )

* angle 0 i 12 o’clock, angle 90 is 3 o’clock  BUT screen Y is upside down so 0 is 6 o’clock and 90 is 9 o’clock

Hello, yes that makes sense… But he didnt want to setLinearVelocity…

–SonicX278