First of all, I admit to being a newbie at this, but I’m hoping someone can help me understand.
I have a very simple scene setup with a gun and a wall.
I am using raycasting with the bullet so that I can get the tag of whatever collider it comes in contact with. This is working perfectly.
I have an if statement in the script on the bullet for contact with anything tagged as a wall so that I can tell the bullet to ricochet off. Right now it just hits and makes a sound.
function Update ()
{
var hit :RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(this.transform.position,fwd,hit,2))
{
//This is for making the bullets perform bouncing off of any object it hits tagged as a wall.
if(hit.collider.gameObject.tag=="wall")
{
AudioSource.PlayClipAtPoint(miniEnemyExplosionSound, transform.position);
}
I am just not able to figure out how to use Vector3.reflect at this point to make the instantiated bullet reflect off of the wall. I understand that I might have to cast another ray at this point, using the normal of the hit object, and get the object following it, but I cant figure out this step.
Anyone willing to help me understand this and get this working? I really need help learning this.