Game Development Community

Item's colliding question

by Camel Taylor · in Torque Game Engine · 03/10/2007 (11:41 am) · 9 replies

Ok let me explain what Im currently doing and were I am trying to go. I am currently working on a prototype for a sports game. My main goal in this project is not to touch the engine code. I wish to do as much as possible in scripts. Now my main problem is the ball I am using. I decided to make the ball from ItemData, after writing some scripts I have the ball set up to work just fine. Except, I realized its time for me to move to the next step. Now her is my problem, when a player runs into the ball it simply passes through it. I need the ball to be able to react to a player as it would a wall and thats to bounce off. I have the scritps set up already that the player cannot catch the ball unless he takes action so if the player holds down the right mouse button the player will pick up the ball. However if the player is not taking action I need the ball to bounce off of him if it comes into contact with him. Is there a way to make items react in such a way? I figured there must be some sort of way. Any help will do, oh and if there is a more correct term used to describe this problem please let me know.

thank you

#1
03/10/2007 (4:50 pm)
Easiest way I can think of is...

function ItemData::onPickup(%this,%obj,%user,%amount)
{
   %pos = %this.position;

   radiusDamage(%this, %pos, 1, 0, "Radius", 1000);
}
#2
03/11/2007 (11:11 am)
Hmm, Im not sure how that works, but I sure will investigate it as soon as I can. I beleave I will start with the wepon.cs and player.cs. Since I know that the player object gets a push back effect when hit. I will post resutlts.
#3
03/11/2007 (11:46 am)
Look up in the scripts for oncollision for each the player and the ball. I am assuming for the ball if you want it to bounce around and such, you made it a rigidshape. Then seet it up to perform an applyimpulse if you condition to catch the ball is not met.
#4
03/11/2007 (6:01 pm)
Is the collision mesh set up for the ball correctly?

Tony
#5
03/11/2007 (6:09 pm)
Oh yeah if you are just trying to pick it up you also have to set up the player to allow it carry that type of item in its inventory.
#6
03/11/2007 (6:10 pm)
If you're using an item for a ball just do what I mention above. The engine automatically does a check for collision between the player and items, my code will make the item bounce off the player. The item will not need a collision mesh as the engine automatically creates collision bounds for items. The only time you need to include a collision mesh for items is if you're using a "destroyableItemType" which means it can be directly hit with a projectile and take damage.

Better yet, do as Ron suggests and use a rigidShape for the ball.
#7
03/11/2007 (6:16 pm)
Quote:
Oh yeah if you are just trying to pick it up you also have to set up the player to allow it carry that type of item in its inventory.

Problem with that is the ball (item) won't bounce off the player. Instead, the player that is hit by the ball (item) will collect it.

His best bet with using an item for the ball is to use the "onPickup' method to determine what to do with the ball upon collision with a player. This way it could either bounce off a player or be caught by a player pending on the needs at the time. Remember, the onPickup method is called on collision with an item; It doesn't necessarily have to be "picked up" for the function to be called. This is why items have a "pickUpRadius" variable.
#8
03/12/2007 (2:08 am)
Ok I have had some time to play around with my problem. A few things to clear up. I do have the ball set up correctly with a keybind. I simply have the logic set up to only pick up the ball and add it to the players inventory if the right mouse botton is pressed. All collsions are being detected I just need to handle them correctly. I am going to read up on rigid bodies and see if I can implement them without any C code changes. If not I have toyed around with a few ideas of how to handle the situation with some random math calcuations and applyimpulse. It may take me a while but I will post some results hopefully by the end of the week.
#9
03/19/2007 (11:39 pm)
In the end I have used the item::collision to grab the collision vector and speed and reversed the order of things to get the ball moving in the oppisite direction. this is what i ended up doing.
%collisionVector = %vec;
%x = getWord(%vec, 0);
%y = getWord(%vec, 1);
%z = getWord(%vec, 2);
%x = -1 * %x;
%y = -1 * %y;
%z = -1 * %z;
%collisionVector = %x SPC %y SPC %Z;
%speed = %speed * 3;
%me.applyImpulse(%collisionVector, %speed );