Mouse and ISO movement

Get help using Construct 2

Post » Fri Aug 10, 2012 2:52 pm

Hi guys and gals. I'm hoping you can help, it seems so simple but I can't seem to get it right. What I want to do is for a condition check for the right mouse button to be down. For actions what I want is for my sprite to move towards the mouse but also start the correct animation within the sprite.For example:
condition on right mouse: action: down move sprite 1 pixel toward andgle(spritex,spritey,mousex,mousey) if angle <=22.5 or >= 337.5 set animation "runningeast" play from beginning.

But when I do it that way it moves the sprite but the animation doesn't trigger. Does anyone have any work around for this? Pretty Please :) Pretty please with cheese on top. :)

Thank you in advance,

Lance

PS this doesn't seem to work at all:
lanceal2012-08-10 14:58:31
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Aug 10, 2012 3:31 pm

It's because when those conditions are met, on every single tick it will just keeps resetting to the first animation frame because you have it as 'play from beginning'

changing it to 'play from current frame' would solve it, but then it would still be unnecessarily setting it's animation every tick still.

A better option would be to make a sub event under this with the condition: 'trigger once'. Alternatively, have a condition to check to see if Knight animation is not equal to "RunningEast"

Either way it will then set the animation and let it play after the first tick.
Also make sure animation properties are set in the image editor
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Fri Aug 10, 2012 3:38 pm

Thanks I did get it to half work. I'm going to change to what you suggested but for the movement I'm still having an issue. When I check for the angle above the mouse doesn't move. When I check for an angle less than say 5 then if the mouse is anywhere above the sprite it moves east. What am I doing wrong with the condition, or is there a better way then I have posted?
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Aug 10, 2012 3:53 pm

angle(knight.x, knight.y, mouse.x, mouse.y)
The angle is between 0 and 180 when the mouse is below the knight. And between 0 and -180 when the mouse is above. If the mouse is directly above the knight, the angle will be -90.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Fri Aug 10, 2012 4:13 pm

Think I got it figured out. I shouldn't have put the angle as a condition because it wasn't comparing the angle, simply grabbing the angle. So I updated the code using the recommendations here and it seems to work. Heres a pic of it now, does it look ok?

https://dl.dropbox.com/u/77974757/Capture1.PNGlanceal2012-08-10 16:14:09
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Aug 10, 2012 4:15 pm

can't seem to make an or block that will allow multiple conditions between each or so I had to post a seperate statement for each angle variance. Unless you all know of a better way?
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Aug 10, 2012 4:52 pm

Alright I think I got it. Please feel free to tell me if there is an easier way. Here's a snap of the current formula:(Note I turned off the change angle on the sprite for the ISO image. If I leave it on the images do not come out right so I added a variable called currentangle to the knight sprite to track the current moving angle)
lanceal2012-08-10 16:55:23
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Fri Aug 10, 2012 5:16 pm

This looks very similar to something I did for a jumping animation, where it's frame was decided by it's angle of direction.
The only different thing I did was use "angle is within 45deg of .." instead of the two greater/less than conditions... one less conditionkeepee2012-08-10 17:17:31
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Fri Aug 10, 2012 6:14 pm

use "(angle+360)%360" to keep any angle always a positive value. Then you can deal with just positive angles and let you add/subtract from angles but still keep the value as an angle. Subtract 90 from an angle to get the traditional "up is 0" angle.

Also you can divide an angle by 4 to get up,down,left,right and divide it by 8 to get those and values inbetween.

That should help ya get more easily useable values from general angles. Specially when it comes to stuff like animation and determining directions
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Fri Aug 10, 2012 7:43 pm

or use an absolute value with abs()
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Next

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 27 guests