How do I prevent an object from clipping into the wall?

Get help using Construct 2

Post » Thu Aug 11, 2016 12:23 pm

I am making a top-down shooter, and I have a last seen object the player leaves when he gets out from the enemy's LOS. When the enemy sees this object, the enemy walks on it. But this usually takes place near the wall. How do I get the enemy to go into the exact place without going inside the wall? Quickly too, I don't want the enemy to seem like it's calculating a straight path.
B
8
S
2
Posts: 55
Reputation: 654

Post » Thu Aug 11, 2016 12:30 pm

If the enemy is going inside the wall, check the size of your collision cells for the path finding behaviour. I assume you're using the path finding behaviour for moving the enemy to this "last seen object" you have?

Also check the collision bounds of the wall objects and the enemy character too, and make sure they're good.

To make the enemy go exactly on the object - check for a close distance (proximity) on the object... once you have this close distance (after using path finding) then turn path finding off and use "moveto" behaviour or some other movement method to go straight to final position. The path finding will work when the enemy is far away (so it will avoid walls and such) but then move to the exact place once within your defined distance (10-20 pixels maybe?).

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
80
S
34
G
40
Posts: 3,029
Reputation: 30,393

Post » Thu Aug 11, 2016 12:43 pm

SoldjahBoy wrote:If the enemy is going inside the wall, check the size of your collision cells for the path finding behaviour. I assume you're using the path finding behaviour for moving the enemy to this "last seen object" you have?

Also check the collision bounds of the wall objects and the enemy character too, and make sure they're good.

To make the enemy go exactly on the object - check for a close distance (proximity) on the object... once you have this close distance (after using path finding) then turn path finding off and use "moveto" behaviour or some other movement method to go straight to final position. The path finding will work when the enemy is far away (so it will avoid walls and such) but then move to the exact place once within your defined distance (10-20 pixels maybe?).

~Sol


I didn't use the path finding behavior, because it doesn't work. The first time the enemy is assigned to find a path, he does and moves like 30 pixels and then stops. Second time he just keeps calculating.
B
8
S
2
Posts: 55
Reputation: 654

Post » Thu Aug 11, 2016 1:55 pm

The path finding behaviour works perfectly... but perhaps you are making some mistakes with it's use. It can be tricky to get it working as expected if you haven't had much experience with it. I don't use it often myself - but I've had some successful experiments with it in the past.

The main things I would suggest to be careful of, is telling the behaviour to calculate the destination path too frequently. Once every 1-2 seconds is usually more than enough unless you have moving obstacles or incredibly fast moving objects. A common mistake that people make it getting the path to calculate every tick or every 0.2 seconds or similar.

Another common mistake is having cell sizes that are not an appropriate sizing for the design of sprites and game environment. Having cells that are too big or too small can make weird things happen.

Moving solids CAN pose problems, but there are even work-arounds and methods for dealing with this also.

I suggest you try path finder again, and use a simpler movement method once close to your point of "last seen".

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
80
S
34
G
40
Posts: 3,029
Reputation: 30,393

Post » Thu Aug 11, 2016 2:15 pm

SoldjahBoy wrote:The path finding behaviour works perfectly... but perhaps you are making some mistakes with it's use. It can be tricky to get it working as expected if you haven't had much experience with it. I don't use it often myself - but I've had some successful experiments with it in the past.

The main things I would suggest to be careful of, is telling the behaviour to calculate the destination path too frequently. Once every 1-2 seconds is usually more than enough unless you have moving obstacles or incredibly fast moving objects. A common mistake that people make it getting the path to calculate every tick or every 0.2 seconds or similar.

Another common mistake is having cell sizes that are not an appropriate sizing for the design of sprites and game environment. Having cells that are too big or too small can make weird things happen.

Moving solids CAN pose problems, but there are even work-arounds and methods for dealing with this also.

I suggest you try path finder again, and use a simpler movement method once close to your point of "last seen".

~Sol


I set the cell size from 30 to 10, and now it works almost perfectly. Thanks!
B
8
S
2
Posts: 55
Reputation: 654

Post » Thu Aug 11, 2016 2:21 pm

Sweet. I'm glad that worked for you!

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
80
S
34
G
40
Posts: 3,029
Reputation: 30,393


Return to How do I....?

Who is online

Users browsing this forum: MainFable, newday198913 and 4 guests