# Particles Follow my vehicles Velocity ? Why?

Particles Follow my vehicles Velocity ? Why?
0.0 0

#1

I am driving a car around that has been added like so

``````//PLAYER VEHICLE OBJECT - DANIEL
playerVehicleObject = new Vehicle();
playerVehicleObject->setAngle(-90);
playerVehicleObject->setPosition(Vec2(-2700 / TIscale, 0 / TIscale));
playerVehicleObject->setSteeringPower(2);
this->runAction(cocos2d::Follow::create(playerVehicleObject->getSprite()));

//SEPERATE CONTACT FUNCTION
bool FirstWorld::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody *contactA = contact.getShapeA()->getBody();
PhysicsBody *contactB = contact.getShapeB()->getBody();

{
CCParticleExplosion* particles = CCParticleExplosion::createWithTotalParticles(6);
particles->setPosition(contactA->getNode()->getPosition());
particles->setAutoRemoveOnFinish(true);
particles->setDuration(0.5f);
this->removeChild(contactA->getNode(), true);
return true;
}

return true;
};
``````

When im driving and the bullet hits the wall, we create particles and set there position to where the contact was. But I notice if my vehicle is moving the particles also move adjacent it as if the particles are on the same layeras the vehicle is. I simple add them both to scene, why would they follow cars velocity. I have played around with the Z-Order with no luck ?

Thanks

#2

Hi there,

#3

But why does this-> mean car. This is in a first world scene in the contact begin function. Why doesn scene pick car randomly and not scene node like it does everywhere else

#4

This does not mean car. Your this is following the car. Thats why the particle looks like its with the car.

#5

But why is this mean car. This means scene in all other functions. Its the ContactBegin function in my first world scene.

#6

Maybe I wasn’t clear.

Here:

#7

How do i simple add them to scene then underneath. ? Is it possible . If I add another sprite , that doesn’t follow car ?

I thought this was the entire scene… Like I can create a sprite and add to this, give it a position and it doesn’t follow car, why does particles do it and not Sprites ?

Particles naturally follow this then it seems or something ?

#8

Any child that is added to this would behave as the particles. It has nothing to do with particles. Actually, is the node parent and child relationship.

In your context, yes, this is actually your scene but you also did this:

`````` this->runAction(cocos2d::Follow::create(playerVehicleObject->getSprite()));
``````