- Home /
Creating a chase obejct for 2D infinite Runner
Hey folks,
I want to create a chasing object for a 2D Infinte Runner and could really use some help! I have no clue how to start...
My current state is the following: I have a character which runs automatically to the right and is able to jump. The ground is generated randomly from an array with preFabs in it, each prefab has it's own obstacles set also, and there are also gaps over which the player has to jump. The player moves only on "one" floor (no floating platforms as for e.g. in the Unity Tutorial). The camera always follows the character, so for the player he basically stays at the same position. When hitting an obstacle, the player slows down.
Now, what I want to create, is an enemy which follows the player and if the player collides with it, the game ends. It should also "ignore" obstacles and gaps or jump over them. I'd like that the chase object may only reach the player if he hits to many obstacles in a short amount of time (say 2 in a second), as the player speed increases again after a while.
So, I got the player speed decreasing after a hit, so I thought about making an object, give it a constant speed and make it run to the right as the character. To avoid it colliding with obstacles, I'd use Physics2D.IgnoreCollision with Layers, but how could I achieve taht it jumps over gaps or ignores them? One solution which came in my mind was to create a empty gameobject for every ground prefab and give it a collider which is identical to the first but without gaps and make the object run on this collider. But this would be very time intensive and probably not very good for the performance, too.
Any ideas? Or tutorials on something like that?
I appreciat any kind of help! Thanks in advance!
Best regards
I managed to create a chaseobject which follows the player at a constant speed, and which jumps over gaps (tagged the gaps and told the chaseobject to add force when colliding with the tagged floor). But now, I can't get the collision with the player to work for some reason o.O