Player-Derived object doesn't move with applyImpulse
by University of Central FL (#0003) · in Torque Game Engine · 06/01/2006 (2:31 pm) · 12 replies
Hello,
I have a blob who can absorb animals called nibblers. If the blob is a certain distance from the nibbler, I want the nibbler to be "sucked" toward the blob. Then, once the nibbler is close enough, the nibbler should respawn, and the blob should be armed with a nibbler weapon with one ammo so it can shoot a nibbler projectile.
Here's the code which is in the AI of the nibblers. The AI think gets called every 100ms:
The first part works fine...if the nibbler is close enough it gets absorbed. The problem I'm having is the applyImpulse on the nibbler object doesn't seem to move the nibbler at all. I've tried scaling the absorbVector dramatically just in case, but no luck. The nibbler is derived from the player class, so applyImpulse should move it, but it doesn't.
Anyone have any suggestions?
Thanks in advance.
I have a blob who can absorb animals called nibblers. If the blob is a certain distance from the nibbler, I want the nibbler to be "sucked" toward the blob. Then, once the nibbler is close enough, the nibbler should respawn, and the blob should be armed with a nibbler weapon with one ammo so it can shoot a nibbler projectile.
Here's the code which is in the AI of the nibblers. The AI think gets called every 100ms:
if( %nibbler.isAbsorbed )
{
// if the nibbler is close enough to the blob to be absorbed, absorb it
if( VectorLen( VectorSub( $player.getPosition(), %nibbler.getPosition() ) ) < $blob_suckInNibblerDistance )
{
echo("Nibbler absorbed!");
// respawn the nibbler
AINibbler::respawn( %nibbler );
//mount the nibbler inside the blob and allow the blob to shoot it
$player.unMountImage(0);
$player.setInventory(TorqueLogoWeapon,1);
$player.setInventory(TorqueLogoAmmo,1);
$player.mountImage(TorqueLogoImage,0);
}
else
{
// the nibbler has been tagged for absorbing but is too far
// we must move the nibbler toward the blob every frame until it is close enough to absorb
// get the vector from the nibbler to the blob
%absorbVector = VectorSub( $player.getPosition(), %nibbler.getPosition() );
// normalize the vector
vectorNormalize( %absorbVector );
// scale the vector by the absorb speed
vectorScale( %absorbVector, 1250 );
//vectorScale( %absorbVector, $blob_absorbSpeed );
// apply an impulse on the nibbler in the direction of the blob
%nibbler.applyImpulse( %nibbler.getWorldBoxCenter, %absorbVector );
}
...The first part works fine...if the nibbler is close enough it gets absorbed. The problem I'm having is the applyImpulse on the nibbler object doesn't seem to move the nibbler at all. I've tried scaling the absorbVector dramatically just in case, but no luck. The nibbler is derived from the player class, so applyImpulse should move it, but it doesn't.
Anyone have any suggestions?
Thanks in advance.
#2
don't you mean %nibbler.getWorldBoxCenter() ?
@orion The reason you need a large number is because the numbers get divided by the shapes mass to keep heavy objects from moving as far
06/01/2006 (3:23 pm)
Simplenibbler.applyImpulse( %nibbler.getWorldBoxCenter, %absorbVector );
don't you mean %nibbler.getWorldBoxCenter() ?
@orion The reason you need a large number is because the numbers get divided by the shapes mass to keep heavy objects from moving as far
void Player::applyImpulse(const Point3F&,const VectorF& vec)
{
// Players ignore angular velocity
VectorF vel;
vel.x = vec.x / mMass;
vel.y = vec.y / mMass;
vel.z = vec.z / mMass;
setVelocity(mVelocity + vel);
}
#3
The mass of the nibbler is not that high so I don't know what the problem is. =(
Anyone else got any ideas?
Thanks in advance.
06/01/2006 (3:32 pm)
I changed getWorldBoxCenter to getWorldBoxCenter() and I increased the force by a LOT and still no luck. The nibbler just sits there until I literally RUN into it with the blob, then it gets absorbed because it is close enough. I just can't seem to move the nibbler with applyImpulseThe mass of the nibbler is not that high so I don't know what the problem is. =(
Anyone else got any ideas?
Thanks in advance.
#4
it all is pretty much the same stuff. cept mines for pushing away, and yours would be for pushing towards
I'll keep staring at your code till i figure it out, in the mean time, start putting echos thruout it and see if all the numbers are accurate and if that section of code is actually being called
::edit::
What is a nibbler? is it a player or a shapebase?
06/01/2006 (3:37 pm)
Alrighty, i'll post some of my code.function pushback(%who, %target){
%vpos = %target.getWorldBoxCenter();
%pushDirection = VectorSub(%vpos,%who.getWorldBoxCenter());
%pushDirection = VectorNormalize(%pushDirection);
// hardoded impluse
%impulse = 5.0;
%mass = 200;//%target.getDataBlock().mass;
%pushVec = VectorScale(%pushDirection,%impulse * %mass);
%pushVec= setword(%pushVec,2,0);
%target.applyImpulse(%vpos, %pushVec);
}it all is pretty much the same stuff. cept mines for pushing away, and yours would be for pushing towards
I'll keep staring at your code till i figure it out, in the mean time, start putting echos thruout it and see if all the numbers are accurate and if that section of code is actually being called
::edit::
What is a nibbler? is it a player or a shapebase?
#5
that's the apply impulse function for shapebase..... it doesn't do anything like for players.
06/01/2006 (3:42 pm)
void ShapeBase::applyImpulse(const Point3F&,const VectorF&)
{
}that's the apply impulse function for shapebase..... it doesn't do anything like for players.
#6
What do I have to use to move players?
06/01/2006 (4:06 pm)
The nibbler is a player. Does this mean I can't use applyImpulse? If this is the problem I'll feel stupid lol.What do I have to use to move players?
#7
Can you verify that it's actually calling the apply impulse function?
06/01/2006 (4:11 pm)
Sorry, i should have read the title of the thread. it says player derived.Can you verify that it's actually calling the apply impulse function?
#8
%object.setvelocity(vectorScale(%object.getforwardvector(),20));
try something like this and see it moves properly. It should cause it to move forward a little
06/01/2006 (4:15 pm)
Let's try something else%object.setvelocity(vectorScale(%object.getforwardvector(),20));
try something like this and see it moves properly. It should cause it to move forward a little
#9
Thanks for all your help =)
06/01/2006 (4:28 pm)
Yeah it looks like setVelocity works. I guess I can just use that to absorb the nibbler.Thanks for all your help =)
#10
Thanks for all your help =)
06/01/2006 (4:31 pm)
Yeah it looks like setVelocity works. I guess I can just use that to absorb the nibbler.Thanks for all your help =)
#11
06/01/2006 (4:40 pm)
Weird. cause all apply impulse does it call setvelocity after it does some division for the mass.
#12
try ridiculously high values. try ten million. hardcode it. be sure you're calling the function, etc.
06/01/2006 (5:54 pm)
Are you sure you're applying enough impulse ?try ridiculously high values. try ten million. hardcode it. be sure you're calling the function, etc.
Associate Orion Elenzil
Real Life Plus
try hardcoding it with something like
%nibbler.applyImpulse("0 0 0", "10000000 0 0");
and working backwards from there.