Main character in physics world - avoid rotating

Hi,

I am having a character in my gameworld that uses physics. But I don’t want him to tumble around when he hits something that he is allowed to.

Any suggestions on how to achieve this?

Thanks, Joakim [import]uid: 81188 topic_id: 15546 reply_id: 315546[/import]

Hey

I’m pretty sure you can use “obj.isFixedRotation” to acheive this, though haven’t tested it myself.

Perhaps someone else could chime in?

[import]uid: 67933 topic_id: 15546 reply_id: 57415[/import]

have a function on enterframe that keeps the hero’s rotation zero

[lua]local function stopHeroFalling()
hero.rotation = 0
end

Runtime:addEventListener(“enterframe”, stopHeroFalling)[/lua] [import]uid: 79135 topic_id: 15546 reply_id: 57416[/import]

The above method will work fine. But another way that will use less memory and avoid using a runtime as spider said

[lua]obj.isFixedRotation = true[/lua] [import]uid: 39088 topic_id: 15546 reply_id: 57425[/import]

A good suggestion Andrew but as skilistican6 suggested, that one line will be more efficient and works perfectly to keep your hero (or other objects) upright. [import]uid: 52491 topic_id: 15546 reply_id: 57471[/import]

Thanks, that was a easy way to do it :slight_smile:

Joakim [import]uid: 81188 topic_id: 15546 reply_id: 57489[/import]

Hmmm, it seems to work as it should but if I rotate the object by code - it start to tumble around again?

player.isFixedRotation = true  
function leanBackward()  
 transition.to( player, { rotation = -20, time=1000, onComplete = leanBack } )   
end  
  
function leanBack()  
 transition.to( player, { rotation = 0, time=800 } )   
end  

Any suggestion on how to solve this?

Joakim [import]uid: 81188 topic_id: 15546 reply_id: 57627[/import]

I did not know about .isFixedRotation.

[lua]player.isFixedRotation = true

function leanBackward()
transition.to( player, { rotation = -20, time=1000, onComplete = leanBack } )

end

function leanBack()
transition.to( player, { rotation = 0, time=800, onComplete= function() player.isFixedRotation = true; end } )

end

[lua] [import]uid: 79135 topic_id: 15546 reply_id: 57648[/import]

I just tested this and it worked as intended. (Version .591)

Do you have sample code you can share to test with? [import]uid: 52491 topic_id: 15546 reply_id: 57722[/import]