[solved]Projectiles Can someone find my disappearing cannonball?
by Johnathan Moore · in Torque 3D Professional · 05/13/2013 (1:37 am) · 12 replies
Hello. My cannonball keeps dissappearing. It fires, archs, hits something, then poof! it's gone. Well, when I say gone, the projectile object is still there, however there is no rendering. I've also dragged it up in the air, and as far as I can tell, it's not dropping down again.
I haven't seen this done in torque I don't think, but I presume the projectile class is capable of this.
Here's my script for the object.
Anyone clued up on this?
I haven't seen this done in torque I don't think, but I presume the projectile class is capable of this.
Here's my script for the object.
Anyone clued up on this?
function TwelvePounderProjectile::onCollision(%data, %proj, %col, %fade, %pos, %normal)
{
}
function TwelvePounderProjectile::onExplode(%data, %proj, %position, %mod)
{
}
datablock ProjectileData( TwelvePounderProjectile )
{
projectileShapeName = $test_dir@"art/shapes/rocks/boulder.dts";
scale = "0.1 0.1 0.1";
directDamage = 1;
radiusDamage = 0;
damageRadius = 0.5;
areaImpulse = 0.5;
impactForce = 1;
muzzleVelocity = 50;
velInheritFactor = 0;
armingDelay = 0;
lifetime = 100000;
fadeDelay = 147200;
bounceElasticity = 2;
bounceFriction = 0.1;
isBallistic = true;
gravityMod = 0.8;
};About the author
Been tinkering with this since I was young.
#2
The players I suppose should be sent flying, and do acrobatics unless hit in the center of gravity.
05/13/2013 (2:23 am)
If it hits the terrain or a building or something, I want it to glance off at the angle it should. I'm sure this could be done with a different class, maybe I could scrap using a projectile for it, if it doesen't do rolling or multiple impacts.The players I suppose should be sent flying, and do acrobatics unless hit in the center of gravity.
#3
You will probably be better off implementing Bullet Physics and than modifying the projectile to use that.
HTH
05/13/2013 (4:06 am)
@OP: This is what Physics was intended for, to handle these types of scenarios.You will probably be better off implementing Bullet Physics and than modifying the projectile to use that.
HTH
#4
05/13/2013 (5:06 am)
Set the armingDelay higher (i.e. to the lifetime of the projectile) and I think you'll see more bouncing. However, there isn't much other control you have over bouncing beyond the elasticity. The onCollision callback can be used to deal damage to objects that are hit along the way.
#5
05/13/2013 (8:09 am)
Yes - what Daniel said. but to add to that, examine the grenade scripts closely. It bounces around before exploding, though it doesn't do damage until it explodes.
#6
"Amount of time, in milliseconds, before the projectile will cause damage or explode on impact.".
I hope that doesn't mean that I wont get any onCollision callbacks while this is active. As as far as I'm aware, that is what causes damage usually, along with on explode.
I'll just wack a echo or breakpoint in and soon find out.
05/13/2013 (8:33 am)
Thanks guys. Daniels idea works. It was armingDelay. This is quite confusingly named. "Amount of time, in milliseconds, before the projectile will cause damage or explode on impact.".
I hope that doesn't mean that I wont get any onCollision callbacks while this is active. As as far as I'm aware, that is what causes damage usually, along with on explode.
I'll just wack a echo or breakpoint in and soon find out.
#7
I changed Projectile::simulate ~1100-~1170
05/13/2013 (9:33 am)
By default it doesn't, I changed mine so it collides, but doesn't explode with armingDelay active.I changed Projectile::simulate ~1100-~1170
if ( hit )
{
// make sure the client knows to bounce
if ( isServerObject() && ( rInfo.object->getTypeMask() & csmStaticCollisionMask ) == 0 )
setMaskBits( BounceMask );
// Next order of business: do we explode on this hit?
MatrixF xform( true );
xform.setColumn( 3, rInfo.point );
setTransform( xform );
mCurrPosition = rInfo.point;
mCurrVelocity = Point3F::Zero;
// Get the object type before the onCollision call, in case
// the object is destroyed.
U32 objectType = rInfo.object->getTypeMask();
// re-enable the collision response on the source object since
// we need to process the onCollision and explode calls
if ( disableSourceObjCollision )
mSourceObject->enableCollision();
// Ok, here is how this works:
// onCollision is called to notify the server scripts that a collision has occurred, then
// a call to explode is made to start the explosion process. The call to explode is made
// twice, once on the server and once on the client.
// The server process is responsible for two things:
// 1) setting the ExplosionMask network bit to guarantee that the client calls explode
// 2) initiate the explosion process on the server scripts
// The client process is responsible for only one thing:
// 1) drawing the appropriate explosion
// It is possible that during the processTick the server may have decided that a hit
// has occurred while the client prediction has decided that a hit has not occurred.
// In this particular scenario the client will have failed to call onCollision and
// explode during the processTick. However, the explode function will be called
// during the next packet update, due to the ExplosionMask network bit being set.
// onCollision will remain uncalled on the client however, therefore no client
// specific code should be placed inside the function!
onCollision( rInfo.point, rInfo.normal, rInfo.object );
if ( mCurrTick > mDataBlock->armingDelay || mDataBlock->armingDelay == 0 )
explode( rInfo.point, rInfo.normal, objectType );
if ( mDataBlock->isBallistic )
{
// Otherwise, this represents a bounce. First, reflect our velocity
// around the normal...
Point3F bounceVel = mCurrVelocity - rInfo.normal * (mDot( mCurrVelocity, rInfo.normal ) * 2.0);
mCurrVelocity = bounceVel;
// Add in surface friction...
Point3F tangent = bounceVel - rInfo.normal * mDot(bounceVel, rInfo.normal);
mCurrVelocity -= tangent * mDataBlock->bounceFriction;
// Now, take elasticity into account for modulating the speed of the grenade
mCurrVelocity *= mDataBlock->bounceElasticity;
// Set the new position to the impact and the bounce
// will apply on the next frame.
//F32 timeLeft = 1.0f - rInfo.t;
newPosition = oldPosition = rInfo.point + rInfo.normal * 0.05f;
}
}
#8
05/14/2013 (3:04 pm)
Ah, good point. Sorry, I'd made the same modification years ago but forgotten about it! I like this way of doing it much better - you get an onCollision callback every time you hit something, and an onExplode callback at the end of the projectile's life. Makes it easy to separate different types of damage.
#9
- Dave
05/15/2013 (11:01 am)
That sounds like an interesting addition. Someone should submit a Pull Request! :)- Dave
#10
Want to see if I can figure out how to make a proper Pull Request lol!
(On a side note can you have more than one Pull Request active?)
05/15/2013 (11:15 am)
Oh let me! Just been at a GitHub course!Want to see if I can figure out how to make a proper Pull Request lol!
(On a side note can you have more than one Pull Request active?)
#11
05/15/2013 (12:01 pm)
Quote:Pull requests are for a branch, so as long as you create a new unique branch (based on development) you can have as many active pull requests as you have branches.
(On a side note can you have more than one Pull Request active?)
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
2nd, if it's necessary for you to not do the swapping: This is the explode method. It turns off a lot of things, you should make sure it doesn't turn off some things you don't want it to turn off...
Furthermore you should have a look at prepareRenderImage
It seems to turn off rendering when the projectile has exploded. You should remove the mHasExploded from that condition.