Particles spawning at the wrong spot?

Hey guys, I just have a particle system with a RigidBody2D component. What I want to do is to spawn some particles where I desire. So, logically I would just have to move the RigidBody2D to where I want the particles to spawn, and then fire emit(). Right? Well, it works, kind of. Let me illustrate.

As you can see, the particles always spawn behind for some reason. I also placed a second character on top of my moving character, just to see if the rigidBody2D was in the right postion. It is, but the particles don’t spawn there.

I can fix that by adding on the Y value of GetRelativePoint, but I don’t like that approach. Anyone know why it’s doing this? I believe this is because the particles are emitting before the particleSystem is moved, but I don’t know why it doesn’t move first and then emit then.

I marked the important parts in between **********.

#pragma strict

function Start(){
    //var sprite : SpriteRenderer = GetComponent("SpriteRenderer");
    particles.emissionRate = 0;
}


var clip : AnimationState;
var sprite : SpriteRenderer;
var Sprite1 : Sprite;
var Sprite2 : Sprite;
************************************************************************************************************************************************************************************************
var particles : ParticleSystem;
var particleBody : Rigidbody2D; //Rigidbody of the particleSystem.
****************************************************************************************************************************************************************
var relativeRightLeg : Vector2;

var timerInterval = 1;
var timerNextTrigger = 0.0f;

var slowDown = false;
var slowDownValX = 6.0;
var speed = 1;   
var vector : Vector2;

function Update () {
    if(Time.time >= timerNextTrigger){
        timerNextTrigger = Time.time + timerInterval;
        executeTimer();
    }

    if(rigidbody2D.velocity.y == 0 && rigidbody2D.velocity.x == 0){
        animator.Play("Idle");
    }else{
        animator.Play("Walk");
        //animator.speed = 1;
    }
   
    if(slowDown){
        slowDownValX = slowDownValX - 0.03;
        var slowDownVal = Mathf.Pow(slowDownValX, 2) / 10;
       
        rigidbody2D.velocity.x = vector.x * speed * slowDownVal;
          rigidbody2D.velocity.y = vector.y * speed * slowDownVal;
    }
   ********************************************************************************************************************************
    //emitParticles(1, rigidbody2D.GetRelativePoint(Vector2(0,0)), 0); //This works completely on-point btw.
****************************************************************************************************************************************************************
}

function executeTimer(){
    leap();
}

function leap(){
   

    var pi180 = Mathf.PI / 180;
   
    vector = Vector2(
    -Mathf.Sin(rigidbody2D.rotation * pi180),
    Mathf.Cos(rigidbody2D.rotation * pi180));
   
    vector.Normalize();
   
   
    rigidbody2D.velocity.x = vector.x * speed;
    rigidbody2D.velocity.y = vector.y * speed;
   
    slowDownValX = 6;
    slowDown = true;
   ********************************************************************************************************************************
    emitParticles(10, rigidbody2D.GetRelativePoint(Vector2(0,0)), 0);
   ********************************************************************************************************************************
    Debug.Log(rigidbody2D.GetRelativePoint(Vector2(0,0)).x);
    Debug.Log(rigidbody2D.position.x);
   
    if(sprite.sprite.GetInstanceID() == Sprite1.GetInstanceID()){
        sprite.sprite = Sprite2;
    }else{
        sprite.sprite = Sprite1;
    }
}
****************************************************************************************************************************************************************
function emitParticles(x : int, p : Vector2, angle){
    particleBody.MovePosition(p);
    particleBody.position = rigidbody2D.position; //I tried moving methods.
    particles.Emit(x);
    //MoveRotation
}
****************************************************************************************************************************************************************

2nd character’s code:

#pragma strict

function Start () {

}

var Rigid : Rigidbody2D; //Body of the original character.

function Update () {
    rigidbody2D.MovePosition(Rigid.position);
    Debug.Log(Rigid.worldCenterOfMass.y);
}

Thanks.

Alright guys, I fixed it. I thought you have to use RigidBody2D to change the positions of something.

This is what I did instead of particleBody.MovePosition();

particleTransform.position = rigidbody2D.position;

That’s all.

1 Like