Bullet sliding against walls instead of bouncing ?

Get help using Construct 2

Post » Tue Oct 15, 2013 3:20 pm

Hello,

I have an enemy with the bullet behaviour.

When he sights the player, his angle goes toward the player.
But if the distance between the player & enemy < 200, his angle changes to angle(playerXY,EnemyXY)+90 or -90, this way he starts to randomly turn around the player.

My problem is when he collides with a wall...I'm preventing collision by using the "bounce off solid" but this gives a pretty bad result as the eneymy keep colliding itself against the wall (until randomly changing his angle again).
So I was wondering, can I make it so the enemy slide against the wall (in the appropriate direction regarding his current angle of motion) instead of colliding with it ? How would I do that ?
Or if you have any other solution to make it so the enemy avoids walls, I'm interrested.

Thanks by advance for your help ! :)
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Tue Oct 15, 2013 4:32 pm

Sounds like you would need to get the vector of the wall facing and use that to calculate the new angle on collision, but I'm not sure if/how you can get that information.

You may want to investigate the custom movement behavior's "push out solid" action.
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Tue Oct 15, 2013 6:25 pm

Straight walls or how does all that look? For straight walls it shouldn't be a big problem.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Fri Oct 18, 2013 11:29 pm

Yes they are straight walls, with atm only 90angles (for floor, side wall & ceiling), but ideally I would also like to have some more fancy angles later..

I've found a formula on this forum about Cosinus & sinus (which I dont really understand..but it's working so far). Im applying it with the help of 2 detectors for X & Y pinned to my ennemy and the event looks like this:

Detector X overlapping wall
--> Enemy set X to self.x-cos(self.Bullet.AngleOfMotion)*self.Bullet.Speed*dt

Detector Y overlapping wall
--> Enemy set Y to self.Y-sin(self.Bullet.AngleOfMotion)*self.Bullet.Speed*dt

That works...but there is still a problem when this happens:
(orange rectangle is Y detector, blue is X)

There, the enemy will just get stuck (if not worst)...as the wrong detector got triggered first.. :/

And if I make both detectors the same size to cover the 4 corners "holes" then it doesnt work at all as they are both triggered at the same time...
I dont know what to do here, I've tried many things but unsuccesfully so far..and as I dont really understand that cosinus formula It's hard for me to "tweak" it, so if anyone could help me on this that would be great, thanks.
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Sat Oct 19, 2013 10:23 am

Try this: http://s000.tinyupload.com/index.php?file_id=89090317209882767491
Maybe breaks at faster bullet speeds and positioning of more crowded angle compositions can be tricky, but other than that works. Ofc you'd need to do that stuff for each enemy.mindfaQ2013-10-19 10:24:12
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat Oct 19, 2013 11:10 am

Well thanks for your help mindfaQ
But unfortunately that doesnt work for what I want to do as I keep modifying the bullet angle of motion, that's why I was going for a "set X,Y" event instead..this way the bullet behaviour is not altered and can continue doing his stuff..
Also there is a problem in your example as the enemy still goes through walls from time to time..

I think the detectors I'm using was a bad idea, and maybe I can trigger the "set X,Y" with something else (like the overlapping at offset ?) but as I said, Im kinda lost with how to change the cosinus formula..
If anyone got an idea, I'd be glad to hear it ! :)
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Sat Oct 19, 2013 6:05 pm

Well I can explain the formula for you:

cos(angle) gives the x-portion of the bullet movement back to you (going right on screen gives a positive value, going left a negative value)
sin(angle) gives the y-portion of the bullet movement back to you (going up = negative, going down = positive)
dt*bullet.speed just is the distance the bullet would travel without interference

so all it does is setting the movement on the overlapped axis back to where it was before the bullet movement of the current tick while retaining the bullet movement of the other axis.

Result: bullet speed is not retained, if you want that you probably need to add the movement you've taken away to the other axis (need a condition construction to not get the signs (+-) wrong)

Result 2: once both overlap, you get no movement at all (in your version) or weird movement (when keeping bullet speed constant); can't really prevent that no matter how the dimensions of the boxes are; only thing you could do is check if movement is frozen and then do a turnaround or slight change in coordinates to allow a fresh approach to the wall (this is probably prefered for you)


so I can imagine that something like this could work:
Detector X overlapping wall
--> Enemy set X to self.x-cos(self.Bullet.AngleOfMotion)*self.Bullet.Speed*dt
--> enemy add "1" to enemy.variable

Detector Y overlapping wall
--> Enemy set Y to self.Y-sin(self.Bullet.AngleOfMotion)*self.Bullet.Speed*dt
--> enemy add "1" to enemy.variable    

for each enemy
-system compare
--> if enemy.variable greater of equal 2: enemy set y to self.y -sin(self.bullet.angleofmotion)*self.bullet.speed*dt
- no condition
--> set enemy.variable = 0
instead of modifying the angle you can also add -sin(self.Bullet.AngleOfMotion) to y to make the enemy take a new approachmindfaQ2013-10-19 18:07:11
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 26 guests