Physics Object Fixed Rotation

Discussion in 'How Can I...?' started by trudnai, Nov 3, 2015.

  1. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Hey Guys,

    I can't seem to find the way to set "Fixed Rotation" for a physics object. Aka I would like to make sure the image is always upright no matter what. So for example if there is an object that slides down on a slope, I wanto to make sure it will never ever roll. Is this possible?

    Thanks!
    Tamas
     
  2. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    WOW, if I do remember my physics days, I don't see how this will be possible except your object has a LOW centre of Gravity and the angle of slope will matter also. What type of object are you trying to achieve this on?
     
  3. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    I know, I am always surprised when Box2D, Chipmunk and other physics engine does not let you to do limitations like that. For non-BB games I had to patch Chipmunk in the other day, I was just hoping BB has already done that.

    It is an enemy type. It is a ball actually but the graphics is not flat so it does not look good when rotates. Maybe I will try to make it as a non physics object and attach to it a wheel, hope that works.
     
  4. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Yeah, just a feedback: If I attach the Enemy to a wheel then everything is super-duper!
     
  5. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    Glad you found a solution. It would be nice you post how you did the setup so others learn from it :D
     
  6. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Ok, here is the mini-tutorial :)

    Problem: Enemy is a physics object, so it falls and on a slope it slides. But as it does that, it is tilted by the slope:

    Screen Shot 2015-11-06 at 11.07.50 PM.png

    This might be the behavior you may want most of the time, but what if not? I have not found any settings similar to character to say "fixed rotation". This is what I wanted to achieve:

    Screen Shot 2015-11-06 at 11.08.21 PM.png

    My solution was this: I have added a wheel:

    Screen Shot 2015-11-06 at 11.15.07 PM.png
    Now I have attached it to the enemy and set both Speed and Torque to 0 for the link (maybe this can be omitted). Make sure you start the link from the wheel so that the enemy will be the child...

    Screen Shot 2015-11-06 at 11.18.18 PM.png

    Then positioned the wheel exactly in the middle of the enemy object:

    Screen Shot 2015-11-06 at 11.19.53 PM.png

    For the wheel object I have opened the physics shape editor:

    Screen Shot 2015-11-06 at 11.22.31 PM.png

    And by default the shape is a rectangle like this:

    Screen Shot 2015-11-06 at 11.23.12 PM.png
    But you may need a circular one:

    Screen Shot 2015-11-06 at 11.23.26 PM.png
    From now you should be able use your enemy like that, however, the wheel is visible:

    Screen Shot 2015-11-06 at 11.31.14 PM.png

    So click on the wheel and "send it back" -- In other words make sure that is behind the enemy object, so you will not see that:

    Screen Shot 2015-11-06 at 11.32.48 PM.png

    If everything went as planned, you should be able to get the desired result:

    Screen Shot 2015-11-06 at 11.08.21 PM.png

    Tamas
     
    Phill Mason and sysads like this.
  7. sysads

    sysads Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    885
    Likes Received:
    353
    Thumbs Up :D
     
  8. Phill Mason

    Phill Mason Serious Boxer

    Joined:
    Sep 25, 2015
    Messages:
    880
    Likes Received:
    721
    Looking forward to seeing how you've used this effect in your game @trudnai.
     
  9. Rebel Studios

    Rebel Studios Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    466
    Likes Received:
    280
    wow wow wow!!! more & more hacks are comin' out eh!! love it :)
     
  10. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Thanks guys!

    BTW you do not have to go very far with your imagination where it could be useful. For example your character has the fixed rotation set and it meets the enemy on the slope. If the enemy is tilted but your character is not, it may look funny:

    Screen Shot 2015-11-07 at 11.11.25 AM.png

    Or if you have a ball that has a non-flat color, like a color graduation or shine on it to look like a real ball, then it looks awful if it rotates down on the slope (maybe the still image does not seem to very bad but when it animates, believe me the effect is terrible):

    Screen Shot 2015-11-07 at 10.49.04 AM.png

    And even worse if the enemy object is not completely round, like a bomb:

    Screen Shot 2015-11-07 at 10.52.31 AM.png

    If you use rectangular collision shape, it may not roll but just tilts and slides on the slope, which might be acceptable, however, it may can roll over if hits a little bump at the end of the slope.
     
    Christoph likes this.
  11. wayne_martell

    wayne_martell Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    301
    Likes Received:
    100
    Just a question guys is there a way to set the weight of your physics object or are they all set the same. I'm trying to do a springboard effect.?
     
  12. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Weight is calculated from the area of the collision shape.
     
  13. wayne_martell

    wayne_martell Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    301
    Likes Received:
    100
    Thanks for the info, so I could link two physics objects together and make it heavier, just use a single pixel PNG with a big collision shape to hide the 2nd object.
    Cheers
     
  14. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Exactly, you can also remove the default animation (single pixel sprite) when you have defined the collision shape, but after that you cannot edit that anymore unless you re-add a sprite.
     

Share This Page