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->addChild(playerVehicleObject->getSprite(), 9);
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();

	if (contactA->getCollisionBitmask() == 3 && contactB->getCollisionBitmask() == 2)
	{
	CCParticleExplosion* particles = CCParticleExplosion::createWithTotalParticles(6);
	particles->setPosition(contactA->getNode()->getPosition());
	particles->setAutoRemoveOnFinish(true);
	particles->setDuration(0.5f);
	this->addChild(particles, 0);
	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,

The follow action is ran on your “this” meaning that “this” node is following your car. Later, particles are added as child of the “this” node. Naturally, your particles would follow your car. You might want to add particles to another parent instead of “this”.


#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. :frowning:


#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()));

You are asking your this(scene) to follow car, that’s why it did.

To get a camera moving feel, you should use camera. Here’s a quick how-to I found:


#9

I see I see !!! OK Ill give that a go in morning. Or tomorrow sometime. 3am nearly, eyes falling out of my head, college at 10:30am :frowning:

Thanks A Half Million !!!