OnCollision Don't Work when player is not moving
by Cinder Games · in Torque Game Engine · 07/06/2005 (1:42 am) · 9 replies
Ok, as the title states, oncollision doesn't work when a player model is not moving.
an example, i have a sword object, which has an oncollision to do damage to whatever touches it. I can stop the AI bot, and then place this sword right in his head and nothing happens. but if he's moving it kills him dead.
I read in a post from May that in player.cc Player::updatePos()
is part of a speed check related to to a speed check of the player. that if the player isnt moving it doesn't do collision check... but i placed a check on there to see if i stopped and kork stopped, it would stop putting that comment in the console. I also just commented that part out too.... didn't seem to make a diff. So that doesn't seem to be the answer...... SOOOO does anyone know how to make this collision work when players are standing still? I've got working melee using mounted static objects and it works good... unless kork stops moving. that's cheating.
an example, i have a sword object, which has an oncollision to do damage to whatever touches it. I can stop the AI bot, and then place this sword right in his head and nothing happens. but if he's moving it kills him dead.
I read in a post from May that in player.cc Player::updatePos()
F32 speed = mVelocity.len();
if (!speed && !mDeath.haveVelocity())
break;
Con::printf("Didn't Break");is part of a speed check related to to a speed check of the player. that if the player isnt moving it doesn't do collision check... but i placed a check on there to see if i stopped and kork stopped, it would stop putting that comment in the console. I also just commented that part out too.... didn't seem to make a diff. So that doesn't seem to be the answer...... SOOOO does anyone know how to make this collision work when players are standing still? I've got working melee using mounted static objects and it works good... unless kork stops moving. that's cheating.
#2
07/07/2005 (10:48 am)
A source object can only collide with a dest object if its moving, otherwise its the dest object colliding with the source object
#3
07/07/2005 (8:23 pm)
I see. so by default shapebases will not check for collisions, only players do? I'll mess around with the collision list check and see if that gets anywhere.
#4
07/07/2005 (8:29 pm)
Only moving objects check for collisions.
#5
07/07/2005 (8:33 pm)
Gotcha. Are you saying then that unless the other player is moving i can't get this to work? is there a way to have it constantly check for collision even when at a stand still? I spend the afternoon trying to figure out exactly where that check is but could't quite figure it out. I'd imagine it does a check on the players velocity.
#6
07/07/2005 (8:37 pm)
Rather, perhaps since the sword is mounted to the player it's not registering the fact it's moving?
#7
07/09/2005 (6:19 pm)
Checking for collisions while still is not a good idea, it's a hack, and it's physically wierd, even. You need the sword to check collision against other objects when it's moving. It would help a great deal if you told us more about this sword of yours. What kind of object it is?
#8
And when i mount it, i don't see why... but it's not updating anything collsion wise during animation. i can mount a the sword, enable all collision and while i can't move.... i can swing the sword all i want.
07/12/2005 (2:37 am)
Well the sword is just a static shape object. it's got a datablock and an oncollision function that causes damage to whatever touches it.And when i mount it, i don't see why... but it's not updating anything collsion wise during animation. i can mount a the sword, enable all collision and while i can't move.... i can swing the sword all i want.
#9
How do I set up the sword (I have the melee resource setup) to collide with barrels, boulders and other objects? I have set up the exploding barrels from Ken Finney's Advanced 3D Game Programming All in One book and they explode just fine when struck with a crossbow bolt. Now, when I strike it with a sword, it doesn't explode, though my sword can kill bots. I suspect it doesn't work with the barrels because I have no SwordProjectile::onCollision method set up in sword.cs. So I tried to set that up using CrossbowProjectile::onCollision as an example and still saw no collisions or explosions. I really want to figure this out because I want to be able to get the sword to do more than just kill bots. I want to cut tall grass, knock rigidshapes around, like my rollable boulders, etc...
Does anyone have any ideas?
08/11/2008 (4:35 am)
I have a question about sword collisions (it's not exactly about the still/moving issue, though):How do I set up the sword (I have the melee resource setup) to collide with barrels, boulders and other objects? I have set up the exploding barrels from Ken Finney's Advanced 3D Game Programming All in One book and they explode just fine when struck with a crossbow bolt. Now, when I strike it with a sword, it doesn't explode, though my sword can kill bots. I suspect it doesn't work with the barrels because I have no SwordProjectile::onCollision method set up in sword.cs. So I tried to set that up using CrossbowProjectile::onCollision as an example and still saw no collisions or explosions. I really want to figure this out because I want to be able to get the sword to do more than just kill bots. I want to cut tall grass, knock rigidshapes around, like my rollable boulders, etc...
Does anyone have any ideas?
Torque Owner Adios, Man!
I don't know what object type you have your sword defined as, but I can use a similar example (I deal more with vehicles myself):
In Vehicle::updatePos() you have access to the variable mCollisionList, which holds a list of Collision objects. Each Collision object keeps track of which object is being hit, along with the point of collision and the collision normal. When updatePos() detects a collision, you can look through mCollisionList and tell those objects that they've just been hit by my car.
Similarly, in your sword's updatePos() function, you can do the same thing. Something like this, but not exactly:
for (i = 0; i < mCollisionList.count; i++)
{
mCollisionList.collision[i].object->hitBySword();
}
The main point being, it's up to the sword object to check for collisions and tell people that they got hit.