# How do I make the 8-Direction behavior slide against walls ?

Get help using Construct 2

### » Tue Nov 03, 2015 10:11 pm

@megatronx
Here's another iteration that adds other units (moving and not) that can push each other around. They're all circles.
https://www.dropbox.com/s/98xzy7n9jrri6 ... .capx?dl=0

@Tokinsom
If you're interested the smooth motion around the corners is done by using voronoi region around the polygon. The light blue region is closest to an edge and dark blue to a corner. It then finds the distance and angle between the object and that point or edge of that region. With that it can calculate how far to move away if too close.
https://www.dropbox.com/s/ethfdnbvqlfij ... n.png?dl=0
Last edited by R0J0hound on Mon Apr 10, 2017 8:44 pm, edited 1 time in total.
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Wed Nov 04, 2015 2:55 am

@R0J0hound Thank you so much for the update! It does everything I could have hoped for darn-near flawlessly! It was pretty easy to integrate into my game, though I had to change one thing to make it properly recognize objects with a negative width or height--just set boxWidth and boxHeight to abs(wall.width) and abs(wall.height). The new example with pushing stuff around looks amazing too! I wish that is what the built-in collision engine did!
B
104
S
38
G
19
Posts: 962
Reputation: 18,026

### » Thu Nov 05, 2015 11:46 am

R0J0hound wrote:@megatronx
Here's another iteration that adds other units (moving and not) that can push each other around. They're all circles.
https://dl.dropboxusercontent.com/u/542 ... units.capx

@Tokinsom
If you're interested the smooth motion around the corners is done by using voronoi region around the polygon. The light blue region is closest to an edge and dark blue to a corner. It then finds the distance and angle between the object and that point or edge of that region. With that it can calculate how far to move away if too close.

@Tokinsom Yes, it should be included in all movement and solids behaviors.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Sat Sep 17, 2016 4:47 am

@R0J0hound This is a really cool example, but its unfortunately pretty heavy on the performance
and it doesn't work with tilemaps without crerating lots of extra collision boxes.

I was trying to achive a similar results with this raycasting plugin.
The benefit would be that it works with tilemaps and i guess it would be faster than an event sheet only version?!?!
Here is a capx of what i've tried so far.

My biggest problem is that i dont know in what direction i should shoot the ray to get the walls normal.
another thing is that i dont know how to calculate at what speed the player would slide along the wall?

It would be awesome if you could take a look at the .capx and give me a hint in the right direction.

Check out my Construct sketches !
Construct sketches are isolated features you can learn from or use in your own projects.
B
87
S
39
G
7
Posts: 102
Reputation: 8,616

### » Sat Sep 17, 2016 6:25 pm

@epicPixel
I found the angle here based on the closest edge or point on the collision polygon, but then if you have that then shooting a ray is excessive. In short even though I thought it over casting rays isn't useful to solve the problem. The most I can think of is to shoot a bunch of rays out and picking the closest one, but that is imperfect.

The sliding is done by correcting the overlap oppiset the angle chosen and the canceling the velocity going in the direction of the angle. That can be done by utilizing a dot product.

The algorithm I used can be made faster by not checking far away objects and/or implementing it in JavaScript. A plugin may be ideal but to me that's a pain to make and maintain.
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

Previous