How to Restrict Movement of Object?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello Everyone,

    I am having a problem with an object in my game. I have the objects angle set to Mouse.X, Mouse.Y but I want to restrict the amount it can turn.

    Being set to the mouse means if I move the mouse around the object , the object will turn a full 360 degrees - I don't want that though. I want the object to be restricted to only moving between 320 and 40 degrees (think a pizza with a slice missing. That missing slice is the angle I'm looking for) How is this done?

    Thank you for looking.

  • Simple.

    Add these events after the 'set angle towards mouse.x,mouse.y'.

    if sprite.angle > 40, and

    if sprite.angle < 180, set angle to 40.

    if sprite.angle < 320, and

    if sprite.angle > 180, set angle to 320.

    I think these will work, but you see my premise.

  • Thank you Squiddster!

    That was driving me nuts. I had the logic down but couldn't figure out the math (I guess I need to pay closer attention in trigonometry class). Of course the angles change depending on the objects direction, but with your template (and the fine education I'm receiving at ITT-Tech), I figured it out.

    You're a life saver - er, better yet - a time saver.

    Thanks again.

    <img src="smileys/smiley32.gif" border="0" align="middle" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • here's an interesting problem...the angle restrictions are working fine as long as the mouse is within the game window. If the mouse cursor leaves the game window through either the top or the bottom the object spins around freely, but not if the cursor leaves the game window through either the left or right side of the screen...weird.

    Anyone know what's going on?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)