x


Particle Effect Instantiating in the Wrong Place

How do I stop the blood splatter from instantiating underneath the enemies? I want them to spawn where the sword hits.

  var isTriggered:boolean;

  function OnTriggerExit(other: Collider)
{ 
if (other.CompareTag("Sword")&&!isTriggered) 
{ 
    isTriggered=true;
    SwordSwing();
 }
}

 function SwordSwing()
 {
 playersStats = player.GetComponent(XPBar);              
 health -= playersStats.playersAttack - defense * .1;

 // create a new blood splat
 var instantiatedbloodParticle : Rigidbody = Instantiate(bloodParticle,   
 transform.position, transform.rotation);
 isTriggered=false;
}
more ▼

asked May 25 '12 at 02:19 AM

BHS gravatar image

BHS
206 27 45 53

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

You can get the point where the collision occurred at, then Instantiate the blood splatter at the point of collision. You can use the normal of the collision to determine which way the particles should squirt from. Here is the reference for Collision contacts. Take a look at the second example, this shows how to use both point and normal.

function OnCollisionEnter(other: Collision)
{ 
    if (other.CompareTag("Sword")&&!isTriggered) 
    { 
        isTriggered=true;
        SwordSwing(other.contacts);
    }
}

function SwordSwing(contacts:ContactPoint[])
{
    playersStats = player.GetComponent(XPBar);              
    health -= playersStats.playersAttack - defense * .1;

    // create a new blood splat

    var point=contacts[0].point;
    var normal=contacts[0].normal;
    var rotation = Quaternion.FromToRotation(-Vector3.up, normal);

    Instantiate(bloodParticle , point , rotation);

    isTriggered=false;
}

You may need to fool around with the rotation. Im guessing it should go in the direction of the sword. You may even do away with the normal and just use the swords direction.

more ▼

answered May 25 '12 at 02:31 AM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

Thanks, but I get an error every time I come in contact with the enemy. It has something to do with the contacts.

May 25 '12 at 06:36 AM BHS
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1677
x640

asked: May 25 '12 at 02:19 AM

Seen: 439 times

Last Updated: May 25 '12 at 06:36 AM