- Home /
Instantiated bullets hitting GameObjects?
How would one go about making instantiated bullets collide with gameobjects? And how would I then script a collision detection - is it any different than with non-instantiated objects?
Answer by Cylon_Toast · Sep 21, 2012 at 05:42 AM
Your question cannot be answered easy. The concept is simple but would be best for you to check out walkerboystudios.com, hover over unity tutorials tab, it drops down and then goton lab 2. it is a 2d space shooter they walk you through step by step to explain things like how to use collision meshes for event triggers. It's very basic and will get you on your way
Answer by Cinematronic · Sep 21, 2012 at 09:55 AM
Attach this to instantiated bullet.
var maxDistance : float = 10000;
function Update ()
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit, maxDistance))
{
if (hit.transform.tag == "gameObjectTag")
DoSomething();
}
Destroy(gameObject);
}
Answer by Hazkin · Sep 21, 2012 at 09:55 AM
No differents. First you need to create a prefab bullets, which contains a script in which you have further process collision. Next use Sendmessage or any other convenient method
Answer by vethan4 · Sep 21, 2012 at 12:38 PM
If your bullet prefab has a rigidbody and a collider attatched, you can use the OnCollisionEnter method to process the collision with another object with a collider. This is probably the easiest thing to do, and is no different to collisions with non instantiated objects.
Your answer
Follow this Question
Related Questions
FPS spawn bullet 0 Answers
Fast bullet ignor collision sometimes 3 Answers
Add force to Instantiated object. 4 Answers