Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
setRotation on a physics body? — Gideros Forum

setRotation on a physics body?

GhandoGhando Member
edited January 2012 in General questions
Looking through the physics samples I noticed the enterFrame function seems to ensure that the location and rotation of a sprite matches its physics body. Instead of using gravity and/or linearVelocity I've been using Gtween to move my objects and I can still use the Enterframe but in this case to do the opposite - set a body to match its sprite - but only with the location.

Is there a way to set the rotation of a body based on the rotation of the sprite?
Sprite's have a setRotation but a body does not. A body DOES have a getAngle but doesn't have a setAngle.

At the moment I'm thinking I'll have to destroy the body and then re-create it inside the enterFrame, setting the updated angle in the createBody call.

Is there another way of doing this?
Tagged:

Comments

  • atilimatilim Maintainer
    edited January 2012
    Hi,

    b2.Body has the function setAngle (in radians). Sorry, it's just missing in the reference manual. You can use setAngle without any problem.
  • GhandoGhando Member
    edited January 2012
    Thanks atilim I just tried
    local deg2rad = (sprite:getRotation() * (180 / math.pi))
    body:setAngle(deg2rad)
    But I'm getting a "attempt to call method 'setAngle' (a nil value)" error.
    I'm using v2011.9 beta3

    EDIT: Just saw the link to beta7 and the above works fine
Sign In or Register to comment.