- Home /
Enemy Move towards object and hold it and use object
Hey ! I want my Enemy to be able to move towards an object and hold it so that he can use it. So for example the enemy moves towards a gun thats already in the scene and when it collides with the Gun he can use it.
I'm not sure how to go about this I'm thinking when the enemy collides with the object the object becomes a parent or child of the enemy and then the enemy can now use it.
And if i what i proposed is right as a solution i'm not sure how to code it. Any ideas or Help with how to tackle this?
All of what you have proposed should work, so what part of this are you in doubt about?
Here's a good place to start:
http://answers.unity3d.com/questions/311844/picking-up-objects-within-range.html
Ins$$anonymous$$d of on mouse click though, you'll just do it on collision.
Also, there are some tutorials on the site if you need some help on how to move an enemy to a target location.
Alright thanks Ill check that out do you think its alright to check collision using the oncontrollercolliderhit function of the character controller or should i check collision with another collider
Answer by iwaldrop · Apr 05, 2013 at 06:15 PM
What you proposed is correct. You want to make the gun a child of a reference transform that is already childed to the enemy object.
ENEMY \ - Reference Transform \ - Gun
As far as scripting it goes, just use a trigger collider, set the position and rotation of the gun to the reference transform, then child it. When it comes to using the gun, the enemy will need a reference to the gun that he's carrying, and be able to 'tell it' to fire. That's really it.