# How to Restrict Movement of Object?

Get help using Construct 2

### » Mon Mar 12, 2012 6:06 pm

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.gamecherry2012-03-12 18:34:00
B
25
S
7
Posts: 79
Reputation: 2,267

### » Tue Mar 13, 2012 12:03 am

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.sqiddster2012-03-13 00:07:10
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Tue Mar 13, 2012 2:15 am

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.

B
25
S
7
Posts: 79
Reputation: 2,267

### » Tue Mar 13, 2012 3:33 am

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?
B
25
S
7
Posts: 79
Reputation: 2,267