Rotation

Is there a way to get the ‘speed’ or value of how fast my player is moving from applyForce?
What I wanna do pretty much is if hes moving to the right I want him to rotate accordingly, if hes moving left to move accordingly. The way I thought it is if I can get the speed value it’d be easy.
if x = negative rotate that way if positive rotate the other way? [import]uid: 77199 topic_id: 23925 reply_id: 323925[/import]

Hi do you not know the force that has been applied within your code? or have you done it through math.random?

How about using getLinearVelocity?
http://developer.anscamobile.com/reference/index/bodygetlinearvelocity [import]uid: 131622 topic_id: 23925 reply_id: 96394[/import]

I did set the force but the player will gradually slow down eventually, that is why I thought it’d be cool to see his speed. But not only that, if I can determine if his speed is negative (going left) or positive (going right) then I can make my player rotate accordingly.

I have tried getlinearvelocity but it doesnt seem to work with force, works fine with setlinearvelocity instead of applyforce, which is obvious i guess but not with applyforce.

I dont need to know the speed if you guys have any other idea how to make the rotation work properly. Pretty much hes set a force and will go until he hits a object, he hits that object forcing him to go the other way, like a ball I want to make it rotate the proper way when going a certain direction. [import]uid: 77199 topic_id: 23925 reply_id: 96427[/import]

How about using a boolean to determine if player moving left or right (for example) however you’re calculating the initial impact/force I presume you know the initial direction the player is travelling(?). make that direction return true, then if player collides again return false. then if currently true return false or if currently false return true etc…

(forgive the crude logic)

– whatever the condition is to make player start moving –
player:applyForce( 1000, 0, player.x, player.y )
local moveRight = true

if – whatever condition makes player move back – then
player:applyForce( -1000, 0, player.x, player.y )
moveRight = false

Use the same calculation of initial impact force to applyTorque and play around with angular damping(?) and Use boolean to set rotary direction too

if moveRight then
player:applyTorque( 100 )
elseif moveRight == false then
player:applyTorque( -100)
I’m quite new to Lua/Corona myself so someone else may have better idea and this is just a rough idea on how to write the code as it’s late and I’m still learning myself, but I hope this might open an avenue for you or spark some inspiration?

Good luck [import]uid: 131622 topic_id: 23925 reply_id: 96442[/import]

ps… check out this code I think it has all the elements you are looking to use, it explains a ball with rotation and how to track its velocity using runtime! They are using linear velocity but there’s no reason you can’t use the speed tracking system with force also as it’s based on x and y position.

http://mobile.tutsplus.com/tutorials/corona/corona-sdk_game-development_basketball/

you can find this and LOADS of tut’s at below site (which is hugely endorsed all over the forums so you may have seen it already), I study all the sample code to pick parts on everything I need, by combining one code with another you can do most anything!

http://www.learningcorona.com/

all the best! [import]uid: 131622 topic_id: 23925 reply_id: 96444[/import]

Thank you very much for taking the time to write in detail and explain everything along with providing links as well, very helpful.

What you said in your second reply is what I kinda did in my first attempt at making my game.

Your way would work but the problem with that is if it falls on top of a box then it will most likely continue going the same way while the collision event would trigger and switch the rotation making it look wrong. Not to mention if I added a slight bounce in the future and it collides multiple times it would constantly rotate different ways.

I used your exact method at first except with setlinearvelocity instead of applyforce and made it so it switches velocity from negative to positive so that it looks like once he hits a wall he goes the other way properly. Except the problem with that is if he falls on top of a box he will go the opposite way because of the collision effect. This is why I ended up switching to applyforce because if i hit a static object with collision the physics will work as intended without any code i might add.

Thank you for trying to help though, I will look at the basketball code now and see if it will helps. Thanks again and have a good day. [import]uid: 77199 topic_id: 23925 reply_id: 96455[/import]