Throwing a ball
by Quentin Headen · in Torque Game Engine · 03/09/2007 (6:08 pm) · 8 replies
I wanted to know if there is a code that will allow a player to throw a ball. I was thinking about something like passing a football or a basketball to another player. Let me know if there is such a code or a tutorial on this matter.
Thank you :)
Thank you :)
About the author
Just your average programmer who tries to finish the projects he starts. :) I am currently focused on creating games with Torque engines. My website is http://phaseshiftsoftware.com
#2
Dealing with throwing a ball for a sports type game introduces some events you will have to code in.
Brief example:
- Throwing the object from the player
- Triggering a "throw" animation on the player
- Setting an arm thread to deal with the player's empty hands once ball is thrown
- The physics of the ball
- Enabling other players to interact with the ball (catch, kick etc)
And so on.
To get you started you could use the stock rigid body physics. This won't provide a good enough solution for a final product however it's the quickest way to get started and will provide you with a template to work from.
03/09/2007 (7:15 pm)
There is some simple stock code which you can use to throw objects from the player. Check out inventory.cs and item.cs for the specifics. This code also has an example of how to create an arc.Dealing with throwing a ball for a sports type game introduces some events you will have to code in.
Brief example:
- Throwing the object from the player
- Triggering a "throw" animation on the player
- Setting an arm thread to deal with the player's empty hands once ball is thrown
- The physics of the ball
- Enabling other players to interact with the ball (catch, kick etc)
And so on.
To get you started you could use the stock rigid body physics. This won't provide a good enough solution for a final product however it's the quickest way to get started and will provide you with a template to work from.
#3
03/10/2007 (8:13 am)
Thanks for that tip Tim. I think I found what you're referring to in the SDK. Even the Shelled! game has script code that helps.
#4
03/10/2007 (11:14 am)
I am still having trouble throwing an object. Helllllllllllllllp Meeeeeeeeeeeeeeeee!!!!! :0
#5
03/10/2007 (5:27 pm)
Download Shelled! (if you haven't already) it comes with the source code now. I have read through the code and found what I needed for throwing/shooting an object with an arc. Mr. Heldna gave some good hints there, on what activities need to happen to make it appear that the ball is being passed and caught.
#6
03/10/2007 (8:53 pm)
Okay, but now I am having trouble making an inventory. Can someone help me with this?
#7
03/10/2007 (9:58 pm)
Is there a way of throwing an object that is not in your inventory?
#8
Yes. This means you'll have to create the item to be thrown.
Example:
03/10/2007 (10:13 pm)
Quote:
Is there a way of throwing an object that is not in your inventory?
Yes. This means you'll have to create the item to be thrown.
Example:
datablock ItemData(ballThrown)
{
className = "Ball";
// Basic Item properties
shapeFile = "~/data/shapes/ball/ball.dts";
mass = 1.5;
elasticity = 0.2;
friction = 0.6;
emap = true;
};
function Ball::onThrowBall(%this, %obj)
{
%item = new Item()
{
dataBlock = ballThrown;
rotation = "0 0 1 " @ (getRandom() * 360);
};
MissionCleanup.add(%item);
%obj.throw(%item);
}
Torque Owner A Herrera