First, report bug templete didn’t load after I pressed post new topic :/ So I’m trying to remember what information to include.
There are 2 problems:
Problem 1: When wallDetector collides with wall or groundChecker isn’t overlapping ground > other wallDetectors position is inaccurate. They stop following their target (enemy).
Problem 2: When player sprite collides with other sprite, this other sprite’s groundChecker’s position is swapped with third sprite. This third sprite is even not part of the collision!!
included capx contains very simplified version of mechanics from my actual game. Principle is same though.
Way I implemented enemies walking/patrolling behaviors is following: there are 2 sprites which serve as helper sprites. They detects when enemy is near wall or not on ground. They are also containers of enemy sprite and are named wallDetector and groundChecker. I’m using boolean to set their position. When boolean is true = follow, false = do not follow.
When wallDetector collides with wall > change enemy’s walk direction.
When groundChecker isn’t overlapping ground > change enemy’s walk direction.
Recreate problem 1 bug:
1. Wait till one of the enemy collides with wall or it’s groundChecker isn’t overlapping ground
2. Other enemies wallDetector position is reset (they stay in place).
Expected results: every enemy’s wallDetector to follow each enemy.
Recreate problem 2 bug:
1. Press right key on keyboard and move player sprite to right
2. Collide with enemy sprite
3. On collision, player’s position is moved by qarp and reset after reaching destination.
4. On collided enemy’s groundChecker will change position to another enemy’s location
Expected results: groundChecker position to stay on correct enemy.
Example capx: h*t*t*p*s://drive.google.com/file/d/1ophpnoj42Kg7BUMnnK0ZZCUWnsFdGjtl/view?usp=sharing
(remove those * -signs to download)
I have no idea how problem 2 is possible because I thought that on collision event takes on consideration only those objects which are colliding. Or I’m doing something wrong in on collision events, which is most likely the case here.
Tested on: Construct 2 r255 and r259.
Chrome
Firefox
Explorer
NW.JS
Used operating systems: Windows 7 and 10.