- Home /
Help with shoot script (JS)
I am creating a game in 3rd person, and I need a shooting script (bullets must come from a specific point in the gun)... I have one but sometimes crashes, undetected the collisions when my bullets go to fast, if someone can pass me some code... basically what i need is, when the bullet collide with the enemy, the bullet destory and enemy too ... soo please help a noob .. thx in advance and sorry for my primitive english i use google translate.
I'm having a similar problem, whihc I posted here: http://answers.unity3d.com/questions/56032/3rd-person-shooting-shooting-where-the-cursor-is
I figured out how to shoot at a point, but I can't seem to get the object to actually move to where I want it to.
Answer by Joshua · May 02, 2011 at 01:06 AM
Don't use collision, use raycasting. Or use DontGoThroughThings.js which uses raycasting. The first is definitely better, but the latter is easier I guess.
for raycast i use in the bullet prefab this script:
function Update() { var dir = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;
Debug.DrawRay(transform.position, dir * 0.5, Color.red);
if (Physics.Raycast(transform.position, dir, hit, 0.5))
{
if (hit.collider.gameObject.tag == "Enemy")
{
Destroy(gameObject);
hEnemy.health -=10;
}
}
}
is right or not?
Your answer
![](https://koobas.hobune.stream/wayback/20220613130748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3rd person shooting - shooting where the cursor is 3 Answers
Instantiate projectile at position of specific game object 1 Answer
How to assign auto target with tag in range?Help! 1 Answer
Why won't my bullets detect a collision and be destroyed?... 4 Answers
First person shooter shoot Function 3 Answers