# Help with a movement behavior plz

Get help using Construct 2

### » Tue Apr 10, 2012 5:20 am

Dude that method u used to calculate his direction is extremely complex hehehe but it works! Somethings u used in the event i have no idea what they are.. like 'floor' and this ">= 315 ? 0 :" part.. but once again thanks!
B
32
S
6
G
5
Posts: 437
Reputation: 6,124

### » Tue Apr 10, 2012 8:13 am

@Noga your formula is overcomplicated

First using the same angle order as c2 (0 is to the right and then you move clockwise) makes the formula way easier.
You can sum it up as round(animationFramCount*angle/360) but as you well representated in your image you need to offset the angle a bit so the direction the sprite shows represents the center of the range of angle and not the minimum.
So it should look like
[code]ceil(animationFrameCount*angle/360-0.5)[/code]
Then to avoid negative result (for angle from 0 to 180/animationFramCount),
you just have to offset values and modulo them
[code]ceil(animationFrameCount*(1+angle/360)-0.5)%animationFrameCount[/code]Yann2012-04-10 08:14:40
B
69
S
22
G
14
Posts: 1,488
Reputation: 16,594

### » Tue Apr 10, 2012 9:31 am

@Yann
I've never been good at math, everything I do is trial/error. Yeah, I didn't know how to offset the angle, so I used conditions. I'll look into your example.

edit> That's exactly what I wanted, just didn't know how. Never though I'd regret I haven't been more attentive at math classes at school, what a paradox. Thanks Yann.Noga2012-04-10 13:45:42
B
26
S
6
G
8
Posts: 774
Reputation: 6,685

### » Tue Apr 10, 2012 2:05 pm

Its possible instead of animations frame, use new animations?? this way i can animate each of them.. im at work now so I didnt ever tried this yet
B
32
S
6
G
5
Posts: 437
Reputation: 6,124

### » Tue Apr 10, 2012 6:13 pm

Yes, use action "Set animation" and name them "0","1","2" and "3". Haven't tried it, but this should work.

Ok, can't use a number as the name, you'll have to use "&" operator.Noga2012-04-10 18:16:50
B
26
S
6
G
8
Posts: 774
Reputation: 6,685

### » Wed Apr 11, 2012 2:17 am

I've implemented the Yann's method and it worked very well, I also used different animations instead of anim.frames so It looked like:
"animation"&str(ceil(4*(1+angle(waypoint.X,waypoint.Y,units.X,units.Y)/360)-0.5)%4)

many thanks to Noga too for those useful tips and solutions ;)
B
32
S
6
G
5
Posts: 437
Reputation: 6,124

Previous

Return to How do I....?

### Who is online

Users browsing this forum: No registered users and 20 guests