- Home /
scripting question
i want to make it so where ever my bullet hits (the ground or an object in the game) something that it lets me know the point in 3d space so i can Instantiate a small smoke particle system so it shows where i hit. how would i go about doing this thank you
Answer by zharramadar · Jan 17, 2011 at 02:05 AM
Indeed, you should clarify your question, and put a more specific title and tags, that would help you getting an answer.
I'll try to answer based on what I got from it...
You are making a bullet, and you want to check where the bullet hits, so in the collision spot, you can instantiate a smoke.
To do that, use Raycast. Take your bullet position and the vector defining the direction the bullet is going through, and make a raycast with it (Physics class).
Then, in the RaycastInfo object (or something like that), you can get the object and where in world coordinates the ray hit an object. Remember that layers count in Raycast, so specify the layers you want to be counted in the raycast or not.
Good luck =D
Hmm doable but to complicated. OnCollisionEnter is way simpler.
Answer by FLASHDENMARK · Jan 17, 2011 at 09:35 AM
Or easy and simple...:
var hitExplosion : Transform;
function OnCollisionEnter (hit : Collision) { if(hit.gameObject) { Instantiate(hitExplosion,transform.position,transform.rotation); } }
Attatch this script to the prefab that you are Instantiating and when it hits it should instantiate a explosion(Particle effects). Just remember to assign the hitExplosion in the inspector and for best effects it should be a particle effect.
Hope this makes sence :)
I think one of the two objects needs to be a RigidBody and maybe be a "Trigger" too?
Hmm. I do believe that only OnTriggerEnter needs one rigidbody.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Instantiate GUI text 1 Answer
How to add a bullet tracer effect to a raycast gun 1 Answer
Shooting Script Bullet Doesnt Fire 2 Answers
Terrain with lots of objects 1 Answer