Game Development Community

Need help with projectiles

by Yost Engineering · in Technical Issues · 10/11/2007 (4:03 pm) · 5 replies

Hello,
I am simply trying to make it so that my player can "throw" a ball in the direction he is facing by clicking mouse button 0. I would also like to be able to detect if the ball hits anything. I am trying to simplify this problem as much as possible, therefore I don't have any type of weapon object, I would like the player to be able to throw the balls directly. I am a beginner with Torque script so I am sure what I have so far is way off but any help or pointers would be appreciated!

datablock ProjectileData( Ball )
{
projectileShapeName = "~/data/shapes/ball.dts";
};

function Balll::onCollision( %this, %obj, %col)
{
///Not sure what to put in here
}

function Throw();
{
%direction = player.getEyeVector();

%p = new Ball()
{
dataBlock = Ball;
initialVelocity = 0;
initialPosition = player.getEyePoint();
};

MissionCleanup.add( %p );

return %p;
}

Some of my major questions include:
How do I access the player object?
How do I determine when the mouse button is clicked?
How do I actually start my projectile moving?

Thanks in advance!

#1
10/11/2007 (4:26 pm)
Imagine ur hand as a weapon, the ball as the ammo.
& try to merge this thought with the crossbow u have in ur Starter.FPS
I'm very sure that it will be possible when u get to understand how it works, all u need is to apply the gravity on the thrown ball & thats supposed to be like an on & off in the ammoData
#2
10/11/2007 (4:29 pm)
All of that stuff is really unecessary. The torque system for projectiles handles aiming, firing, etc... If you want to get a look at it open the crossbow.cs file in the starter.fps

And it would be simplest to set the ball as a weapon and projectile. You would set the ball to be like a weapon, and another ball for the projectile. Think of it as holding the ball in hand is considered the weapon, and clicking fires the ball projectile, it's not memory intensive at all and is the simplest to code. You can even use that as something of a sample. Just take out all the explosion data, set the damage to 0 and change the shapename to your ball model. Set isBallistic to true if you'd like your ball to arc, not for it to continue straight until it collides, or times out.

function BallProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
//Add whatever code you want. Checking collision mask types, special effects, etc...
}

I might not be much help but I tried :p
#3
10/16/2007 (7:56 am)
Thank you, that actually helped a lot, now my remaining question is if I wanted to use this outside of the starter FPS what files do the crossbow.cs depend on? I have put crossbow.cs and item.cs in my project and added the exec("....") lines into game.cs but they still do not show up in the world creator window.
#4
10/16/2007 (8:30 am)
Check the log & c what the errors are, probably u'll need some images stuff from the data folder (non scripts files) but double check from the Log
#5
10/21/2007 (3:45 pm)
Use crossbow.cs, item.cs, weapon.cs, radiusdamage.cs (without this. the explosion will not work), and then from the data folder, go to shapes, copy the "crossbow" folder.

exec() those 4 scripts. And I would suggest creating the directory for the crossbow folder the way it was in starter.fps "starter.fps/data/shapes/[copy crossbow here]" because in here all the data and graphics are contained for particle effects and weapon/ammo models. It has to be the same directory path because it is called as that in the crossbow.cs script or you will have an *invisible* crossbow and bolt. Or you can just rewrite all the lines that call that as the path.