How do rotate a sprite within certain angles?

Get help using Construct 2

Post » Wed Jan 28, 2015 7:29 pm

I have a cannon sprite that is set to rotate towards the mouse position.

Every Tick-> Cannon.Set Angle -> Mouse.X & Mouse.Y

This works great the cannon sprite rotates around following the mouse.

I want it to only rotate between certain angles though. I don't want it to be able to rotate straight up, down, or behind.

So I add a condition that it only rotate when the cannon is between two angles (X&Y).

This brings the problem that when it reaches either X or Y it stop following the mouse all together.

Any ideas on how to remedy this?
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Wed Jan 28, 2015 8:17 pm

set another sprite at the same position of the cannon, set its angle towards mouse position.
Set the cannon angle to the sprites angle but with a condition where you check if its in your angle range.

I think there is an more effiecent way but i dont worked a lot with angles yet so this is the only methode that comes in my mind right now.
Maybe someone other knows a better way for it.
Read this:
yeah, i really like to say that you should "Read this:"
B
14
S
7
Posts: 138
Reputation: 1,740

Post » Wed Jan 28, 2015 8:24 pm

Thank you so much, I was racking my brain like crazy. It may be crude but damn if it don't work beautifully.
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Wed Jan 28, 2015 8:39 pm

you could do it like this
You do not have the required permissions to view the files attached to this post.
B
257
S
42
G
15
Posts: 1,992
Reputation: 41,415

Post » Thu Jan 29, 2015 3:05 pm

@Lordshiva, that's how I did it originally. The problem with that is when they have the mouse on top of the cannon it wont move. Like if the mouse is below your cannon it wont move.
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Thu Jan 29, 2015 6:50 pm

Have you tried using clamp?

clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.
B
10
S
2
G
1
Posts: 13
Reputation: 671


Return to How do I....?

Who is online

Users browsing this forum: plinkie, RIDETHEPIG and 7 guests