How do I determine moving angle or save last position?

Get help using Construct 2

Post » 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
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » 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
30
S
7
G
4
Posts: 31
Reputation: 4,913

Post » 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
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » 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
30
S
7
G
4
Posts: 31
Reputation: 4,913

Post » 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
28
Posts: 2,493
Reputation: 20,950

Post » 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
28
Posts: 2,493
Reputation: 20,950

Post » 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
30
S
7
G
4
Posts: 31
Reputation: 4,913

Previous

Return to How do I....?

Who is online

Users browsing this forum: KTML5 and 20 guests