How to detect when a character has collided with a wall
I am trying to code an enemy's movement, where the enemy would detect the player in front of them, and if the player was there for more than 6 seconds they would charge forward in a straight line to where the player is (or was if the player moves out of the way quickly enough). However, I am having trouble detecting when the enemy has hit a wall sprite or the player. Is there a way to detect when they've hit a wall?
I have tried using Component Overlap to do this, however, it needs to be casted to something, and I am unsure on how I would cast a sprite to this. I have also tried to use the Component Hit command but I have no idea how to use it to be brutally honest. I have also tried using a for while loop, but this just causes an infinite loop, which leads to the game crashing.
My enemy is a floating shadow fist.
I am using the Flying character movement, as this fist will spawn after my character has pressed a button in the level, once the fist has spawned it will float up and down in the centre of the room aiming towards the player, the player has to aim the fist to a weak area of the wall which once the fist hits will be destroyed, but without being hit by the fist itself. This is the code I am using (Without any loops or variable to tell if it has hit a wall) I wanted my fist to move back first then move forwards continuously until it hits either the player or a physical barrier (e.g. a wall), however, my walls are sprites, not entities so I am unsure of how to cast them in a component overlap command and don't know how to use the component hit command.
I was able to fix my problem myself. I was able to bypass the infinite loop crashes by using custom events, and I have made a box trigger that I can easily place over my walls, so when my Shadow Fist overlaps it, it will set the Boolean variable 'Hit Something?' to true. This also happens when overlapping my character.
Now I just need to set up my Shadow Fist's Attack Reset and it will be complete.
answered Apr 22 '19 at 02:39 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here