Quantcast
Channel: Answers by "doomprodigy"
Viewing all articles
Browse latest Browse all 90

Answer by doomprodigy

$
0
0

Heres one. I use raycast for my guns so this should work.

if (Physics.Raycast (gunPos, direction, hit, bulletRange)) {
        //Check if we hit something
        if (hit.rigidbody){
            // Apply a force to the rigidbody we hit
            hit.rigidbody.AddForceAtPosition(bulletHitForce * direction, hit.point);

            //Send a message to the hit object so its aware that is hit so it can take apropriate action
            //like applying damage to itself
            hit.collider.SendMessageUpwards("ApplyDamage", bulletDamage, SendMessageOptions.DontRequireReceiver);

            //If show Gizmos is turned on you will be able to see a red line between the gun and the hit object
            //this is for debugging purposes only
            Debug.DrawLine(gunPos, hit.point,Color.red);
        }
        //Show spark where bullit hit
        if(Smoke) //Check if the object exists
        {
            Smoke.transform.position = hit.point;
            var rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
            var Smoke: GameObject = Instantiate (Smoke, hit.point , rotation);
   }
}

(Included other part of script inside my weapon script to show my placement)

Peace, Aaron Lewis

Note: You need a GameObject called smoke at the top of your script.


Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>