0 Favourites

How to Restrict Movement of Object?

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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" />

  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
233 22,245
TiAm's avatar
TiAm
Unread hot topic
167 14,490
DMT2005's avatar
DMT2005
Unread hot topic
0 Favourites
Path Movement Behavior
98 52,470
R0J0hound's avatar
R0J0hound