- Home /
Player should move box, Ai shouldn't
So I have a gameObject (crate) that the player should be able to push left and right but in comes the Ai and starts moving it too. I want the Ai to not be able to move it at all but still be able to collide with it so it doesn't go through it.
Any suggestions?
Answer by TonyLi · Jul 09, 2013 at 01:58 PM
If you're using NavMeshes for navigation, you could add a NavMeshObstacle to the crate.
Looks like that requires pro which I am unfortunately not using. I am using move-to and it's all 2D based with just X as the movement.
Since this is 2D and you're using $$anonymous$$oveTo, here are a couple options:
In your AI's Update() loop, Raycast straight ahead. If the raycast hits something, stop moving. Or,
Add colliders to the crate and the AI character. In your AI script, add a function OnCollisionEnter() that sets a bool blocked to true. Add a function OnColliderExit() that sets blocked to false. In your Update(), only move if !blocked.
Your answer
Follow this Question
Related Questions
Help with a chasing script 2 Answers
Can I make Ai using only a focus script and a bullet script? 1 Answer
Moving a box. 1 Answer
Determining rotation for collision avoidance? 3 Answers
Player rotating after wall collision 1 Answer