0
votes

When my player gameObject collides with another gameObject, I want to keep the player from leaving a small area around this other gameObject until the player has defeated the enemy. In other words restrict the movement of the play until the enemy has been dealt with. I just don't know how to restrict the movement temporarily to a small amount of space local to where the initial collision took place.

I think possible solutions are to clamp the transform, or to create a another gameObject to physically keep the player in this area using rigidbody and a collider.

My player controlled movement right now is simply Input.GetAxis for both vertical and horizontal input and using transform.translate.

Thanks for reading my question. Any help would be appreciated, even something you might think is obvious, I'm still new to this. Thanks a lot.

1

1 Answers

1
votes

Without knowing any details about your game (2D,3D,etc.) my initial thought for doing something like this would be to spawn invisible wall gameObjects around your player and the enemy they collided with. Action games like Devil May Cry do this a lot, except they have pre-defined level spots where the walls are going to spawn.

When the player defeats the enemy, you could delete the walls.