How to create clientside particle?
by Tuanlucky · in Torque Game Engine · 05/05/2006 (11:30 pm) · 9 replies
Hi,
I am trying to create some effect that only see in client. For example, selecting aura around the player or NPC.
I tried this code to create an aura particle when player created. And that particle will follow the player whereever he is. This particle used as a symbol that user easily recorgnize controlled character in crowd.
file server/script/game.cs at the end of function createPlayer()
file client/script/game.cs
But the result is all clients see all aura on every character.
What I expect is each client only can see the aura on their character not other client character.
I am trying to create some effect that only see in client. For example, selecting aura around the player or NPC.
I tried this code to create an aura particle when player created. And that particle will follow the player whereever he is. This particle used as a symbol that user easily recorgnize controlled character in crowd.
file server/script/game.cs at the end of function createPlayer()
CommandToClient(%client, 'CreateParticleFollow',%player, %emitter, %emitterdata);
file client/script/game.cs
function clientCmdCreateParticleFollow(%player, %emitter, %emitterdata)
{
//Tuan = =Set up particle Ring 5.5
%tform = %player.getTransform();
$playerPRing = new ParticleEmitterNode()
{
emitter = %emitter;
position = getWords(%tform, 0, 2);
rotation = getWords(%tform, 3, 6);
datablock = %emitterdata;
target = %player;
};
$playerPRing.setFollowTarget(%player); //my function to set this particle follow this player.
}But the result is all clients see all aura on every character.
What I expect is each client only can see the aura on their character not other client character.
#2
You can then use .scopeToClient to specify wich clients see the particles. Hope that helps
05/06/2006 (1:38 am)
I just did this myself. here is the code i used:class ClientParticleEmitterNode : public ParticleEmitterNode
{
typedef ParticleEmitterNode Parent;
public:
ClientParticleEmitterNode();
DECLARE_CONOBJECT(ClientParticleEmitterNode);
};
IMPLEMENT_CO_NETOBJECT_V1(ClientParticleEmitterNode);
ClientParticleEmitterNode::ClientParticleEmitterNode()
{
// Todo: ScopeAlways?
mNetFlags.clear(Ghostable);
mTypeMask |= EnvironmentObjectType;
mEmitterDatablock = NULL;
mEmitterDatablockId = 0;
mEmitter = NULL;
mVelocity = 1.0;
}You can then use .scopeToClient to specify wich clients see the particles. Hope that helps
#3
05/06/2006 (2:25 am)
Greats, thanks you guys.
#4
class ClientParticleEmitterNode like this
But when i run, i cant not see Particle, seem it only create in server. And I try to debug by putting a break point at if (isClientObject()) in ClientEmitterParticleNode::OnAdd(). It never go inside the codeblock.
05/06/2006 (6:38 am)
I tried Peter's Method with these code on client/script/game.csfunction clientCmdCreateParticleFollow(%player, %emitter, %emitterdata)
{
//Tuan = =Set up particle Ring 5.5
%tform = %player.getTransform();
$playerPRing = new ClientParticleEmitterNode()
{
emitter = %emitter;
position = getWords(%tform, 0, 2);
rotation = getWords(%tform, 3, 6);
datablock = %emitterdata;
target = %player;
};
$playerPRing.setFollowTarget(%player);
echo("Add Ring");
}class ClientParticleEmitterNode like this
class ClientParticleEmitterNode : public ParticleEmitterNode
{
typedef ParticleEmitterNode Parent;
public:
bool onAdd();
ClientParticleEmitterNode();
DECLARE_CONOBJECT(ClientParticleEmitterNode);
};
IMPLEMENT_CO_NETOBJECT_V1(ClientParticleEmitterNode);
ClientParticleEmitterNode::ClientParticleEmitterNode()
{
// Todo: ScopeAlways?
mNetFlags.clear(Ghostable);
mTypeMask |= EnvironmentObjectType;
mEmitterDatablock = NULL;
mEmitterDatablockId = 0;
mEmitter = NULL;
mVelocity = 1.0;
}
bool ClientParticleEmitterNode::onAdd()
{
if(!GameBase::onAdd())
return false;
if (!mEmitterDatablock && mEmitterDatablockId != 0)
{
if (Sim::findObject(mEmitterDatablockId, mEmitterDatablock) == false)
Con::errorf(ConsoleLogEntry::General, "ParticleEmitterNode::onAdd: Invalid packet, bad datablockId(mEmitterDatablock): %d", mEmitterDatablockId);
}
if (mEmitterDatablock == NULL)
return false;
if (isClientObject())
{
ParticleEmitter* pEmitter = new ParticleEmitter;
pEmitter->onNewDataBlock(mEmitterDatablock);
if (pEmitter->registerObject() == false)
{
Con::warnf(ConsoleLogEntry::General, "Could not register base emitter for particle of class: %s", mEmitterDatablock->getName());
delete pEmitter;
return false;
}
mEmitter = pEmitter;
//=== Tuan add 5.5
ShapeBase* tptr;
mTarget = NULL;
if(mTargetID != -1)
if(Sim::findObject(mTargetID, tptr))
{
mTarget = tptr;
}
//== end
}
mObjBox.min.set(-0.5, -0.5, -0.5);
mObjBox.max.set( 0.5, 0.5, 0.5);
resetWorldBox();
addToScene();
return true;
}But when i run, i cant not see Particle, seem it only create in server. And I try to debug by putting a break point at if (isClientObject()) in ClientEmitterParticleNode::OnAdd(). It never go inside the codeblock.
#5
05/06/2006 (8:20 am)
As far as I know, this is not possible without some major rewrites.
#6
05/06/2006 (8:24 am)
Its actually alot simplier than you have it. You create the particle effect on the server just like any normal effect. The only difference is this object will not ghost to any client by default. Once created, you just call %particleNode.scopeToClient(%client); and only that client will see the particles.
#7
Here is my code to move the EmitterNode
05/07/2006 (6:24 am)
Thanks for your advises. I had tried and succeed. But now I got another problem when I want the particles follow a player. I can make it follow a player. But when moving the camera out of the EmitterNode, the particle will be disappear even the particles had moved to center of screen. I think the problem is from the camera scope. I try to fix this by moving the EmitterNode along player. But seems It only affects in client side. When I press F11, I see the EmitterNode still stay where It was created. Here is my code to move the EmitterNode
void ParticleEmitterNode::advanceTime(F32 dt)
{
Parent::advanceTime(dt);
Point3F emitPoint, emitVelocity;
Point3F emitAxis(0, 0, 1);
getTransform().mulV(emitAxis);
getTransform().getColumn(3, &emitPoint);
emitVelocity = emitAxis * mVelocity;
// Another the type of Particles. Ring Particle.
if (mEmitter->isRing())
{
//Has target to follow?
if (mTargetID != -1)
{
ShapeBase *playerObj;
if(Sim::findObject(mTargetID, playerObj))
{
emitAxis = Point3F(0,0,1);
playerObj->getTransform().mulV(emitAxis);
playerObj->getTransform().getColumn(3, &emitPoint);
//Make the EmitterNode follows target too
setTransform(playerObj->getTransform());
}
//Make Emitter follows target.
mEmitter->followTarget(mTargetID);
}
mEmitter->emitRingParticles(emitPoint, emitAxis);
}
else
mEmitter->emitParticles(emitPoint, emitPoint,
emitAxis,
emitVelocity, (U32)(dt * mDataBlock->timeMultiple * 1000.0f));
//=== Tuan end change
}
#8
I want each player to have a particle emitter mounted on them, but only seen by the player it is attached to.
Right now, I have my emitter created and I mount it to the player and I'm trying to use scopetoclient limit it to the one player. But in this set up, the host can see all of the player's emitters.
this code is in GameConnection::createPlayer(%this, %spawnPoint) inside
server/script/game.cs
09/18/2009 (7:47 pm)
I've come upon this thread and I'm wondering if scopeToClient also works in multilayer.I want each player to have a particle emitter mounted on them, but only seen by the player it is attached to.
Right now, I have my emitter created and I mount it to the player and I'm trying to use scopetoclient limit it to the one player. But in this set up, the host can see all of the player's emitters.
this code is in GameConnection::createPlayer(%this, %spawnPoint) inside
server/script/game.cs
$stillEmitter = new ParticleEmitterNode()
{
datablock = ParticleData;
emitter = flotsamEmitterStill ;
};
$stillEmitter.scopeToClient(%this);
%player.schedule(50, mountParticleEmitter, $stillEmitter, "mount5");
MissionCleanup.add($stillEmitter);
#9
09/21/2009 (3:17 pm)
Nevermind, I've found my problem.
Torque Owner Paul /*Wedge*/ DElia
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6504