Change angle based on collision (steering)

Get help using Construct 2

Post » Fri Apr 25, 2014 1:23 pm

I have a sprite moving at an angle, when it collides with a sprite I want to change the angle so it doesn't move through it.

Image

I want the moving sprite to basically steer the angle away alongside the wall so it glides past it rather than through it (no matter what angle the sprite or walls are when they collide). This is so I can make movement around obstacles smooth without halting.

If anyone knows how math then please help! Thanks.
B
147
S
74
G
20
Posts: 1,786
Reputation: 22,522

Post » Fri Apr 25, 2014 6:11 pm

Digging though my capx files I found a couple solutions.

Here I did wall sliding that works best when the wall angle is 45 degrees from the angle of motion.
viewtopic.php?f=147&t=91933&p=719471&hilit=event_motion2.capx#p719471

And here I used SAT in one and used the custom movement behavior in the other to compare. The first is spot on perfect but the moving object is treated as being perfectly round and it only works with rectangular walls.
viewtopic.php?f=147&t=95108&p=736233&hilit=slide3.capx#p736233

Hope that helps.

PS.
SAT stands for the Separating Axis Theorem and basically gives more info about a collision such as penetration depth and closest direction to resolve the collision.

EDIT:
Another idea that is more like steering is to use two detector sprites attached to the moving sprite. Then when they overlap a wall one turns clockwise until it's not overlapping and the other turns counter-clockwise. The just set the angle of motion to whichever detector that turned less.

https://dl.dropboxusercontent.com/u/542 ... steer.capx
B
91
S
31
G
103
Posts: 5,241
Reputation: 67,768

Post » Sat Apr 26, 2014 8:20 am

@R0J0hound Wow, that's beautiful thanks a lot!

I like your 2nd link in particular, the steer.capx is similar to a thought I had but yeah it uses quite lot more collision checking.
B
147
S
74
G
20
Posts: 1,786
Reputation: 22,522


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest