Game Development Community

Thrown items are going through walls (DIFs)

by Robert Luke · in Torque Game Engine Advanced · 06/12/2007 (2:28 pm) · 3 replies

I have an item that the player 'throws'. I have an interior that is built using 6 cubes (meaning it is fully enclosed).

When I throw an item it goes through the walls sometimes! It seems that when the velocity of the item is high, it happens a lot more. When the velocity is low, it still happens sometimes.

The item will go through the middle of a surface! It is not like this is only happening at corners!

Bottom line, what in the heck is going on. Why is the collision detection failing?

Is this a common problem that the community knows about? Is there an easy fix? Am I going to have to re-write the collision code (please no!!!!).

On a similar note, when my character picks up an item I attach it using the .mountImage fx call (i.e. the item is 'on' the character through a ShapeBaseImage). The item is bigger than the collision surface of the character. So if I walk up to a wall and then throw the item, it goes through the wall (i.e. the no collision on the ShapeBaseImage means that it was on the other side of the wall by the time I threw it!).

Thanks!

#1
06/12/2007 (2:52 pm)
Read the description (shapebase.h) for ShapeBaseImage's and you'll understand why there's no collision for these objects. They are not regular scoped networked objects, just datablocks that are used to simulate a new shape on the shapeBase class it is attached to.

As for your actual problem, then it's hard to tell when no one knows at what velocity your items are travelling at. If they go higher than intended then yes, bad things can happen.
#2
06/12/2007 (10:24 pm)
Thanks for a response. However, lets look at what was asked again. I apologize for not being as specific as possible. I have the details laid out below (I hope that is all of them).

------------------------------------------------------------------------------------------------------------------

First off, you state that

"If they go higher than intended then yes, bad things can happen."

What is "higher than intended"? Is there a limit, and if so, what is it? Also, why is that the case?

In addition, what do you mean by "bad things can happen"? I would say that not colliding is bad w.r.t. collision testing. Is there something else that I should know about?

Here are my details

------------------------------------------------------------------------------------------------------------------

GENERAL PROBLEM:

Items being thrown through a wall! In particular, Items passing though surfaces in a DIF.

This does not necessarily happen in corners, meaning it is not always at the "seam points" of surfaces in a DIF (locations where surfaces in a DIF touch). It happens a lot in the middle of a wall. Also, it does not necessarily happen upon initially leaving (the throw) the player, but it can happen as the Item bounces around inside of the DIF (eventually goes out of the DIF). I stand in the middle of my DIF and throw the ball, so I am not "on" or "at" the surface, but standing back from it.

I also get a fair amount of times where the thrown item "sticks" to a wall (as if it is lodged into the wall) ... ?

------------------------------------------------------------------------------------------------------------------

CONTEXT:

Here is my Item description and the throw code

datablock ItemData( MyGameBall )
{
sticky = false;
mass = 1;
elasticity = 1.0;
friction = 0.0;
static = false;
rotate = false;
maxVelocity = 100;
gravityMod = 3.0;
shadowEnable = true;
shadowCanMove = true;
shadowCanAnimate = true;
shapeFile="~/data/shapes/myball/myball.dts";
};

Here is the core of the throw item algorithm
[in a function ShapeBase::throwObject(%this,%obj) that I call on a particular key press]

//Get the direction of the object doing the throwing (its our player)
%e = %this.getForwardVector();
//Scale that vector by 10 (the scaling reason will become apparent below)
%vec = vectorScale(%e, 10);
//Add the players velocity to this scaled vector (so it goes faster when you are moving)
%vec = vectorAdd(%vec,%this.getVelocity());
//Get where the person is
%pos = getBoxCenter(%this.getWorldBox());
//Add the persons location to a scaled version of the forward vector
//this is our 'offset' from the players center (simple way to try to avoid it being in the player when thrown)
%pos = vectorAdd(%pos,vectorScale(%e,2));
//Set this value to the balls general transform
//puts the ball in front of the player
%obj.setTransform(%pos);
//Apply an impulse to the ball
//this is what sends the ball on its way
%obj.applyImpulse(%pos,%vec);

------------------------------------------------------------------------------------------------------------------

I can provide information about the DIF scene if necessary, but the walls that I can throw an item through are collidable by the player. So if there is a constraint related to the speed of an entity, the design of surfaces in a DIF related to collision, or some special hangup for items, then please let me know.

------------------------------------------------------------------------------------------------------------------

Upon request I can also provide the model and details about it. The collision surface is concave and has very few number of faces (<15). I have a Col-1 and a LOSCol-9.

------------------------------------------------------------------------------------------------------------------

On a last note, I am sorry about not being very specific on the last paragraph in the initial email. Basically, I know about the ShapeBaseImage and the 'documented' reason for no collision, so I was wondering if anyone has thought of a creative way to get around the problem. That is, using a ShapeBaseImage for displaying an item attached to the player, and if it is larger than the players collision area, making sure that it does not go through a surface.

We wonder if turning the ball back into a shape/item as the throw animation is started will help any?
#3
06/13/2007 (2:21 am)
Quote:
Robert Luke said:
I apologize for not being as specific as possible.

No worries.

Quote:
Robert Luke said:
What is "higher than intended"? Is there a limit, and if so, what is it? Also, why is that the case?

Higher than intended would be higher than what the code is designed for. Remember, we are using legacy code from Tribes II and it just wasn't needed to have objects flying at light speed back then.

Quote:
Robert Luke said:
In addition, what do you mean by "bad things can happen"?

The object could penetrate the surface it is colliding with. RigidShape or vehicle's show this quite a bit if you go crazy.

Quote:
Robert Luke said:
Is there something else that I should know about?

There are without doubt a ton of things you should know about :) But I can't list all of them and you'll have to find them yourself or search some more about the areas which interest you.

Quote:
Robert Luke said:
Items being thrown through a wall! In particular, Items passing though surfaces in a DIF.

You have to stop typing, and try to help yourself so we can help you :) There are things you can do to isolate the issue, but you haven't mentioned any.

* What happens when you slow down the throw? Does the collision get more reliable?
* Have you tried with any of the stock weapons?
* Have you made any changes to the collision code?

100 velocity isn't too much. Shouldn't honestly be a problem.

Quote:
Robert Luke said:
That is, using a ShapeBaseImage for displaying an item attached to the player, and if it is larger than the players collision area, making sure that it does not go through a surface.

There is functionality for this which will bump back your weapon if you head into a wall. But for that to work, you need to set a retraction node (search the forums) and make sure the bounding box is correct because it will be used for collision.