1

Can someone please show me how I would limit the zRotation "it's rotatable range" of an SKPhysicsJointPin physicsbody object from its starting point.

I currently have an issue when I use shouldEnableLimits that forces my physicbody object to move unexpectedly/glitch when its rotation is rotating from +270degrees into -90degrees (from positive to negative etc) so I need to use another way to achieve this limiting rotation that lowerAngleLimit and upperAngleLimit provided.

I have a physicbody that is continually moving all over the screen and I use:

myobject.physicsBody applyTorque:lateralMove" //(+ and -)

to rotate this body left and right. As the body is moving I just need the body to be only able rotate in a set amount / "range" as it moves around the screen.

I'm not sure how I go "hey object your center point is here, you can't zRotate past -0.7 (left) or 0.7 (right) from your center etc".

Been racking my brain for over a week on how I can do this, any help would be great

///////////// Heres whats happening if I do a test case

if (_myobjectdegrees > 265) { 
    NSLog(@"please don't glitch!");
    myobject.zRotation = -1.5f;

}

//heres my consoles output

current zrotation 2.949927

current zrotation 3.002563

current zrotation 3.033562

current zrotation 3.061646

please don't glitch!

current zrotation -1.500000

current zrotation 0.212812

current zrotation 1.947406

current zrotation -0.485760

current zrotation -2.326967

current zrotation -2.381383

// it glitched, the numbers after I set -1.5 should start be going back to -1.49, -1.48 back to 0.

//myobjectdegrees is an integer converted to degrees from radians based of my myobject.zRotation

I find I do

//if (myobject.zRotation > 4.6) {

This case is hardly ever triggered. The object is constantly moving/rotating.

TF35Lightning
  • 365
  • 3
  • 7
  • 22
  • You can manually set the rotation if it exceeds your threshold, which can easily create a mess in the simulation (ie exploding joints). This is why physics limits are soft rather than rigid. – CodeSmile Nov 06 '14 at 10:01
  • Hi LearnCocos2D thanks for the reply, I've made an edit above to show you whats going on, to get around that glitch when its rotates from +270degrees into -90degrees (from positive to negative etc) and leaving shouldEnableLimits = YES and lowerAngleLimit and upperAngleLimit set to a number, I thought I might be able to simply manually rotate the node myself and set its zRotation to -89 for example, but unfortunately it still does a glitch in the animation / zRotation calculation, see above etc, as you can see after I've set it to -1.5 etc – TF35Lightning Nov 06 '14 at 11:11
  • LearnCocos2D any idea why this is happening, or have an idea on how I can get around it? – TF35Lightning Nov 07 '14 at 02:57

0 Answers0