Quantcast
Channel: Latest Questions by Macdude2
Viewing all articles
Browse latest Browse all 38

View entire object when on intersection of wall

$
0
0

I am building a game where there are many walls surrounding the player. He is fighting and one of the weapons is a grenade that can land on walls and blow up when he presses a button. However, when these grenades hit the intersection of my wall, the player can only see half of the grenade or half the grenade is not attached to any wall.

How can make it so that the grenade is always touching the visible part of the wall and does not go through it or lay over of it AND if it does happen to go over, move the grenade so it looks like it is on the wall. I am trying to make something similar to the grenades you can throw in NOVA 2. Thanks for any help.

Here is the code that I already have. It is similar to the codes used on the machine gun that comes with unity.

function FireBig () {

    var direction = transform.TransformDirection(Vector3.forward);
    var hit : RaycastHit;

    // Did we hit anything?
    if (Physics.Raycast (transform.position, direction, hit, range)) {
        // Apply a force to the rigidbody we hit
        if (hit.rigidbody)
            hit.rigidbody.AddForceAtPosition(force * direction, hit.point);

        // Place the particle system for spawing out of place where we hit the surface!
        // And spawn a couple of particles
        if(hit.collider.CompareTag("Wall")){
        if (BigGrenade){
            BigGrenade.transform.position = hit.point;
            BigGrenade.transform.rotation = Quaternion.FromToRotation(Vector3(-100,0,1) , hit.normal);
                        }
        }
        if(hit.collider.CompareTag("NotWall"))  
                {
        if (hitParticles) {
            hitParticles.transform.position = hit.point;
            hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
            hitParticles.Emit();
        }
            }       // Send a damage message to the hit object          
        hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    }

    bulletsLeft--;

    // Register that we shot this frame,
    // so that the LateUpdate function enabled the muzzleflash renderer for one frame
    m_LastFrameShot = Time.frameCount;
    enabled = true;

    // Reload gun in reload Time        
    if (bulletsLeft == 0)
        Reload();           
}

Viewing all articles
Browse latest Browse all 38

Trending Articles



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