- Home /
 
EteeskiTutorials' bullets (raycast bullets with gravity)
Hi, for my game I used EteeskiTutorial's bullets from one of his series ( http://www.youtube.com/watch?v=kx7PcUzhG_8&list=PLfAMZpOjTmpbr9EN9FwK76Hdr_bWMDxdH ), I only used the tutorial [1/5] though because it's the only one that I need for my game, the problem is that the bullets in my game compared to his are huge, but with this I mean like, they are slow, and have almost same widht as a player/enemy, so how can I make multiple raycasts so it hits with the true size of the object? since you probably won't watch a tutorial just to help me, here, have my script (and it's actually in c#, he did it in js)
 public class Projectile : MonoBehaviour {
 
     public float speed = 100f;
     public float lifeTime = 7f;
     public GameObject decalHitWall;
     
     [HideInInspector]
     public Vector3 moveDirection;
     [HideInInspector]
     public float shortestSoFar;
     
     [HideInInspector]
     public Vector3 instantiatePoint;
     [HideInInspector]
     public Quaternion instantiateRotation;
     [HideInInspector]
     public bool foundHit = false;
     
     public bool damagePlayer = false;
     public int damage = 20;
     
     void Awake () {
         moveDirection = transform.forward * speed;
         shortestSoFar = Mathf.Infinity;
         foundHit = false;
         
     }
     
     void Update () {
         transform.rotation = Quaternion.LookRotation(moveDirection);
         RaycastHit[] hits;
         hits = Physics.RaycastAll(transform.position, transform.forward, speed * Time.deltaTime);
         foreach (var hit in hits){
             float tempDistance = Vector3.Distance(transform.position, hit.point);
             if(tempDistance < shortestSoFar){
                 instantiatePoint = hit.point;
                 instantiateRotation = Quaternion.LookRotation (hit.normal);
                 shortestSoFar = Vector3.Distance(transform.position, hit.point);
                 foundHit = true;
                 GameObject spawnParticles = (GameObject)Instantiate (decalHitWall, instantiatePoint, instantiateRotation);
                 if(hit.transform.tag == "Enemy" && !damagePlayer){
                     hit.transform.parent.GetComponent<EnemyScript>().health -= damage;
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                     Destroy (transform.root.gameObject);
                 }
                 if(hit.transform.tag == "Player" && damagePlayer){
                     hit.transform.GetComponent<Player>().health -= damage;
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                     Destroy (transform.root.gameObject);
                 }
                 if(hit.transform.tag == "LevelPart"){
                     Destroy (transform.root.gameObject);
                     shortestSoFar = Vector3.Distance(transform.position,hit.point);
                 }
             }
         }
         
         transform.position += moveDirection * Time.deltaTime;
         
         lifeTime -= Time.deltaTime;
         
         if(lifeTime <= 0f){
             Destroy(gameObject);
         }
     }
 }
 
               Thanks in advace
yeah but... could you write a script? I don't know how I could put 3 raycast's information in only one....
You are already raycasting once in your scene. Just do it 2 more times.
Thanks, it worked, convert into an answer so I can accept it please, and the bullets sometimes go trought enemies, but this happens since the first time I tried them, it's really weird I must talk to eteeski himself
Answer by amphoterik · Jul 24, 2013 at 03:18 PM
Just cast multiple rays from the bullet. One in each "corner" and the middle should do.
Your answer