Author Topic: Setting the initial velocity of a duplicating projectile isn't working  (Read 1868 times)

I'm attempting to get around this 30 second limit for projectile objects that I keep hitting by duplicating the original and then deleting the original.

Code: [Select]
function takeGameProjProjectileClass::onExplode(%this,%obj) {
%client = %obj.client;

if(%obj.markedForExplosion) {
%client.play2D(takeProjExplode);
if(%obj.combo > %client.highestCombo) {
%client.highestCombo = %obj.combo;
}
if(%obj.combo >= 20) {
%color = "<color:" @ RGBToHex(getColorIDTable(%client.color)) @ ">";
$DefaultMinigame.messageAll('',%color @ %client.name SPC "\c6obtained a\c3 x" @ %obj.combo SPC "combo!");
}
cancel(%obj.positionLoop);

Sky.flashColor(%client,1);

%client.saveTakeGame();
return parent::onExplode(%this,%obj);
}

%proj = new Projectile(TempProjectile) {
dataBlock = %obj.dataBlock;
initialPosition = %obj.getPosition();
initialVelocity = %obj.getVelocity();
position = %obj.getPosition();
rotation = %obj.rotation;
scale = "1 1 1";
sourceObject = %obj.sourceObject;
sourceSlot = %obj.sourceSlot;
client = %obj.client;
originPoint = %obj.getPosition();
sourceClient = %obj.sourceClient;
combo = %obj.combo;
};
MissionCleanup.add(%proj);
%proj.setName("Laser" @ %proj.getID());
%client.projectile = %proj;
%proj.checkPosition();
%obj.delete();
}

It correctly duplicates the projectile for the most part, except its velocity is set to 0 (and therefore I don't know if the trajectory is correct either). %proj.setVelocity() also doesn't exist.

Is %obj.getvelocity returning anything? Perhaps it's considered no longer moving once it explodes

Is %obj.getvelocity returning anything? Perhaps it's considered no longer moving once it explodes
It's returning vectors like
Code: [Select]
-3.30187e-006 1.4839e-006 1
1.35877e-007 -3.61744e-006 1
1.35877e-007 -3.61744e-006 -1

Averaging the absolute values of each part gives ~0.3 as a result.
Code: [Select]
%vel = %client.projectile.getVelocity();
%speed = mFloatLength((mAbs(getWord(%vel,0)) + mAbs(getWord(%vel,1)) + mAbs(getWord(%vel,2)))/3,1);

So either that suspicion is confirmed or your projectile is extremely slow by your design

Assuming the former though so try packaging weaponImage::onFire or projectile::onAdd and scheduling a function in (projectile.lifetime - something) milliseconds that deletes the projectile/recreates one
« Last Edit: April 09, 2015, 06:45:11 PM by Headcrab Zombie »

Doing that didn't work, but switching from %obj.getVelocity() to %obj.getLastImpactVelocity() seems to to the trick well enough.

I think this will work:

Code: [Select]
function takeGameProjProjectileClass::onExplode(%this,%obj) {

//stuff here

%obj.setName("MYOLDPROJECTILE");

%proj = new Projectile(TempProjectile : MYOLDPROJECTILE) {
initialPosition = %obj.getPosition();
initialVelocity = %obj.getVelocity();
originPoint = %obj.getPosition();
};
MissionCleanup.add(%proj);
%proj.setName("Laser" @ %proj.getID());
%client.projectile = %proj;
%proj.checkPosition();
%obj.delete();
}

edit: Didn't see your last post
« Last Edit: April 09, 2015, 10:35:29 PM by Greek2me »


Averaging the absolute values of each part gives ~0.3 as a result.
Code: [Select]
%vel = %client.projectile.getVelocity();
%speed = mFloatLength((mAbs(getWord(%vel,0)) + mAbs(getWord(%vel,1)) + mAbs(getWord(%vel,2)))/3,1);


That's not how to get an object's speed.  Use vectorLen(%obj.getVelocity()); instead.

Code: [Select]
%proj = new Projectile(TempProjectile : MYOLDPROJECTILE) {

Just a note, while object inheritance requires a name for the parent object (i.e. a variable cannot be passed, only an object name), the new object does not need to be named. You may as well use this:

Code: [Select]
%proj = new Projectile(:MYOLDPROJECTILE) {