Mouse Click movement set "direction" of sprite

Get help using Construct 2

Post » Wed Apr 18, 2012 6:42 pm

How do I make it so when I click it determines which way I am moving so I can tell it which animation to play. I am using rex_moveto target position of object behavior to do the mouse click movement. I am doing a roguelike movement system.

I'm new to Construct and new to the forums so idk what all is needed to get a question answered, but let me know and I will edit it into the main post.SYNYST3R12012-04-18 18:43:10
B
2
Posts: 5
Reputation: 260

Post » Wed Apr 18, 2012 7:01 pm

compare the location of the moving object to the location of the click.

object.x < click.x = to the left it should face right.
object.y < click.y = to the top it should face down.

etc. then play the right animation
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Wed Apr 18, 2012 7:06 pm

That is the first thing I tried, but it liked to animate up and down when I was going left or right. Only doing two directions works perfect, but once I add all four directions it doesn't work correctlySYNYST3R12012-04-18 20:14:01
B
2
Posts: 5
Reputation: 260

Post » Wed Apr 18, 2012 9:57 pm

I like this method:

On Left Mouse Button Down
--> Set Angle of Motion = round(angle(object.X, object.Y, mouse.X, mouse.Y) / 90) * 90

If you wanted it 4 way, it'd be 90 (90 * 4 = 360). If you wanted it 8 way, then you'd change 90 to 45 (45 * 8 = 360). It will go to whatever the closest angle is. Then I like to do:

If Moving
Compare Object.8Direction.Angle of Motion = 0
--> Set Animation Walk Right
Compare Object.8Direction.Angle of Motion = 90
--> Set Animation Walk Down
Compare Object.8Direction.Angle of Motion = abs(180)
--> Set Animation Walk Left
Compare Object.8Direction.Angle of Motion = -90
--> Set Animation Walk Up

There are more ways to do it, but I like that method well enough.
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Wed Apr 18, 2012 11:04 pm

Using angle of motion rotates my sprite. I am doing it now by comparing the player position and two imagepoints. It is working pretty well so far. SYNYST3R12012-04-18 23:05:42
B
2
Posts: 5
Reputation: 260

Post » Sun Jan 06, 2013 8:49 pm

SYNYST3R1, can I have a cap.x file of only the code you used to rotate your sprite?
B
4
S
1
G
3
Posts: 2
Reputation: 1,956

Post » Sun Aug 31, 2014 12:51 am

Message: JxOxKxExR can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
https://cloud.mail.ru/public/96c41d239a ... oving.capx
B
5
S
2
Posts: 2
Reputation: 517


Return to How do I....?

Who is online

Users browsing this forum: SpartCrafter and 19 guests