UN-sinus/cosinus OR GetVelocity to movment angle

Hello everyone and thank you in advance to all the helpers.

My main problem is that I need to get the angle of movment and I thought about doing that through the getVelocity function.

(The body moves to one direction while facing elsewhere) 

I’ve found a way but i need to be able to take a number and Un -sin it for the equation but I can’t find the syntax to do it.

P.S

If anyone have a better way to calculate the movment direction it will be good also.

Your question is a little confusing. Describe in terms on actions and response what you want your game object to do, and we’ll try to help from there.  Forget the math and possible implementations for now.

Regardless, let’s talk about the movement you’re trying to accomplish and solve it that way.

Yes to the first one, I am trying to convert the direction an object is moving into an angle.

code example :

local Ball = display.newCircle( centerX, centerY, 10 )

Ball.x = centerX

Ball.y = centerY

Ball:setLinearVelocity( RandomVx,  RandomVy )

Now the ball is moving, how can I get the rotation so he would be facing the direction he’s moving.

(I know I can do it the other way around (chosing rotation and than finding the vx and vy) but it’s only an example, in my app I can’t do it)

Also, how do I solve that equation with corona:

sin(x) = Num – find x, Num is known.

Nah, just grab a math library like this one:

https://github.com/roaminggamer/SSKCorona/blob/master/ssk/RGMath2D.lua

If you use just this file, place it in the same folder as main.lua  and do this:

local math2d = require "RGMath2D" local ball = display.newCircle( centerX, centerY, 10 ) local randomVX = math.random(-100,100) local randomVY = math.random(-100,100) ball:setLinearVelocity( randomVX, randomVY ) local vx,vy = ball:getLinearVelocity() ball.rotation = math2d.vectorToAngle( vx, vy )

PS - Please format code in code blocks in future posts

https://raw.githubusercontent.com/roaminggamer/RG_FreeStuff/master/ForumsImages/formatyourcode.jpg

I made some corrections so look at the latest post.

Thank you very much, it works.

Your question is a little confusing. Describe in terms on actions and response what you want your game object to do, and we’ll try to help from there.  Forget the math and possible implementations for now.

Regardless, let’s talk about the movement you’re trying to accomplish and solve it that way.

Yes to the first one, I am trying to convert the direction an object is moving into an angle.

code example :

local Ball = display.newCircle( centerX, centerY, 10 )

Ball.x = centerX

Ball.y = centerY

Ball:setLinearVelocity( RandomVx,  RandomVy )

Now the ball is moving, how can I get the rotation so he would be facing the direction he’s moving.

(I know I can do it the other way around (chosing rotation and than finding the vx and vy) but it’s only an example, in my app I can’t do it)

Also, how do I solve that equation with corona:

sin(x) = Num – find x, Num is known.

Nah, just grab a math library like this one:

https://github.com/roaminggamer/SSKCorona/blob/master/ssk/RGMath2D.lua

If you use just this file, place it in the same folder as main.lua  and do this:

local math2d = require "RGMath2D" local ball = display.newCircle( centerX, centerY, 10 ) local randomVX = math.random(-100,100) local randomVY = math.random(-100,100) ball:setLinearVelocity( randomVX, randomVY ) local vx,vy = ball:getLinearVelocity() ball.rotation = math2d.vectorToAngle( vx, vy )

PS - Please format code in code blocks in future posts

https://raw.githubusercontent.com/roaminggamer/RG_FreeStuff/master/ForumsImages/formatyourcode.jpg

I made some corrections so look at the latest post.

Thank you very much, it works.