# How do I determine moving angle or save last position?

Get help using Construct 2

### » Tue Feb 14, 2017 3:59 pm

Virpoja wrote:@Lamar, thanks.

I guess I am being kind of picky but I want to stay away of using "wait 0.1" etc. stuff, since I want really responsive and crisp implementation.

I am already using variables to store last position and using that to calculate the correct angle. That works pretty well too. I think I have to find some way to store the last position (just before collision) to prevent "angle of motion" updating to 0.

Well if you can click faster than 0.1 seconds you have some fast reactions lol!

You can remove those and they were put in for using tap and I forgot to take them out. Runs fine without them.

Anyway, what I gave you works and use it if you want or not. Have a good day!
Banned User
B
29
S
7
G
58
Posts: 1,229
Reputation: 34,910

### » Tue Feb 14, 2017 4:18 pm

Ok, I updated the example. https://dl.dropboxusercontent.com/u/137 ... n_ve2.capx

Now you can also strafe by holding ALT key. In example you can see that collision detector sprite is always on the correct position. (even if you hold ALT, Left Arrow, Forward Arrow at the same time)

So that is working great... Except when it matters, when the collision is detected.

SO the thing i need is a sure way to "save" the last position before collision to maintain the correct angle instead of it updating to 0.

Anyone have any ideas?
B
31
S
8
G
4
Posts: 31
Reputation: 5,040

### » Tue Feb 14, 2017 4:34 pm

Using the last position to get the angle of motion isn't suitable in this case since from a stop the angle of motion will always just be 0. It needs to be moving for one frame to get a direction. However, notice that the angle of motion is connected to the object's angle and the input. So for example you could do this:

up arrow
--- angleOfMotion = sprite.angle

down arrow
--- angleOfMotion = sprite.angle+180

strave left
--- angleOfMotion = sprite.angle-90

strave left
--- angleOfMotion = sprite.angle+90
B
97
S
36
G
131
Posts: 5,514
Reputation: 83,466

### » Tue Feb 14, 2017 5:11 pm

Damn... And I thought I had a good solution. Thank you @R0J0hound and every one else for your suggestions. I think I will tinker around little bit more with the example provided by @99Instances2Go. Maybe try to implement some basic AI using that method.

Again, thank you all for your help
B
31
S
8
G
4
Posts: 31
Reputation: 5,040

### » Tue Feb 14, 2017 7:34 pm

Gave it second though.
This what you actually want to do ?
https://www.dropbox.com/s/yc33l4u1d8e4f ... .capx?dl=0
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Tue Feb 14, 2017 11:19 pm

@Virpoja

Forbidden to use behaviors is hard.
Yet, lets try a smoother 8directions imitation.

https://www.dropbox.com/s/jkjo2yn5hcl1g ... .capx?dl=0
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Wed Feb 15, 2017 8:00 pm

Oh man, thanks so much @99Instances2Go!

Second implementation is really sweet but it was actually this:
"distance(Sprite.X,Sprite.Y,Sprite.LastX,Sprite.LastY) > 0,1"

This is one of those: "how in hel..... I did not think that" moments.... I was sure there is a simple solution that I just can`t think of... and it was this.

So thank you again for your efforts, Construct community prevails again. (as it always does)
B
31
S
8
G
4
Posts: 31
Reputation: 5,040

Previous