Game Development Community

Mounting effects on Spawn problems.

by Terra Snover · in Torque Game Builder · 09/20/2011 (7:45 pm) · 5 replies

Okay I'm running into a bit of a problem with mounting particle effects on player spawn.
I added the following to "game/gameScripts/PlayerMethods.cs" and the effect will get added to the game but it is not mounting to the actor.


///Called when a player Spawn
function PlayerClass::onSpawn( %this )
{
// Play the spawn effect.
%this.PlaySpawnEffect();
}


/// Called when a player respawns
function PlayerClass::onRespawn( %this )
{
// Load the checkpoint data
loadCheckPoint();

// Remount the camera
%this.mountCamera();

// Update the gui
%this.updateHealthGui();


//little one particle effect on spawn
// Play the spawn effect.
%this.PlaySpawnEffect();
}


//on spawn play particle effect
function PlayerClass::PlaySpawnEffect( %this )
{
// Create effect.
%spawnEffect = new t2dParticleEffect()
{
SceneGraph = %this.getSceneGraph();
EffectFile = "game/data/particles/littleonesmoke.eff";

Position = %this.getPosition();
Rotation = %this.getRotation();
Size = "5 5";
};

// Play Effect.
%spawnEffect.playEffect();
}


any help would be nice I am new to programing and am lost.

#1
09/21/2011 (2:32 am)
Try to changing like this:
//on spawn play particle effect
function PlayerClass::PlaySpawnEffect( %this )
{
// Create effect.
%spawnEffect = new t2dParticleEffect()
{
    SceneGraph = sceneWindow2D.getSceneGraph();
    Class = "SpawnEffectClass";
    Position = %this.getPosition();
    Rotation = %this.getRotation();
    Size = "5 5";
};

// Load Effect
%spawnEffect.loadEffect("~/data/particles/littleonesmoke.eff");

// Play Effect.
%spawnEffect.playEffect();
}
#2
09/21/2011 (9:35 am)
Is mount() called from somewhere else or it is just missing?
#3
09/21/2011 (10:40 am)
@ Suharian. that did not work. The code supplied slowed the game to the point it was un-playable. and the particle effect did not spawn.

@Rpahut. No looking there is no mount() code. Every time I tried putting it in there it froze up the game. where would that code live?
#4
09/21/2011 (1:58 pm)
Okay here is the entire code with the mount stuff:


///Called when a player Spawn
function PlayerClass::onSpawn( %this )
{
// Play the spawn effect.
%this.PlaySpawnEffect();
//----------
%this.attachToPlayer();
//----------
}

/// Called when a player respawns
function PlayerClass::onRespawn( %this )
{
// Load the checkpoint data
loadCheckPoint();

// Remount the camera
%this.mountCamera();

// Update the gui
%this.updateHealthGui();


//little one particle effect on spawn
// Play the spawn effect.
%this.PlaySpawnEffect();
}

//on spawn play particle effect
function PlayerClass::PlaySpawnEffect( %this )
{
// Create effect.
%spawnEffect = new t2dParticleEffect()
{
SceneGraph = %this.getSceneGraph();
EffectFile = "game/data/particles/littleonesmoke.eff";

Position = %this.getPosition();
Rotation = %this.getRotation();
Size = "5 5";
};

// Play Effect.
%spawnEffect.playEffect();
}

//Mount to player
function PlayerClass::attachToPlayer( %this, %linkTarget )
{
%this.mount( %this.positionTargetMountToCell,
getWord( %tLinkLocalPoint, 0 ),
getWord( %tLinkLocalPoint, 1),
100, true, false, false, false);
}


but I am still running into the problem where the effect will spawn but not mount.
#5
09/22/2011 (4:22 am)
function PlayerClass::attachToPlayer( %this, %linkTarget ){
   %this.mount( %this.positionTargetMountToCell,
      getWord( %tLinkLocalPoint, 0 ),
      getWord( %tLinkLocalPoint, 1),
      100, true, false, false, false);
}

What it does is trying to mount player
to whatever is in %this.positionTargetMountToCell, probably nothing. Also %tLinkLocalPoint is not assigned with any useful value and thus holds "".

It should probably looks more like this in your case:
// attach object to this
function PlayerClass::attachObject(%this, %object) {
    %object.mount(%this, %localPointThatIsActuallyValid, 0, true, false, false, false);
}
You'll have to provide some value for %localPointThatIsActuallyValid variable. I'm pretty sure you can get away with just "0 0", but it's up to you to decide. And when you call it, make sure you pass your effect in as %object parameter.