Game Development Community

Turret question

by David Tan · in Torque Game Engine · 09/30/2004 (12:25 am) · 47 replies

I learning from the turret resource:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5345

I can mount the turret to a Vehicle,but I can not control turret with mouse.
What I wanted is:
a)control vehicle with keyboard.
b)control the turret with mouse,rotate around.
c)In 1st person view,looking where the turret is aiming.

Could somebody help me? Thanks.
#21
10/08/2004 (7:42 am)
Thanks Tim,it is very userful to everybody!Thanks again.
#22
10/13/2004 (7:25 pm)
With the help of Raverix, Now I can control the vehicle with keyboard and control the turret with mouse.It works fine.Is it possible looking where the turret is aiming in 1st person view?I study it for many days but can't get the way.Could somebody give me more idea?
#23
10/13/2004 (11:27 pm)
I'm sorry if I can't directly help you tyq.fk, but I have some question about what you do.

First of all, I have something similar to you : I move the vehicle with the 4 arrow and the turret with the mouse (rotate and up/down).
In 1st person view I look where the turret canon aim, and in 3rd person view I look at the vehicle direction (like the cam view of the buggy in the starter.racing).
But I have (temporary) removed the turret code, and I use the standard player code with a turret model. So my turret is a mounted player, it's a 2 levels scheme :
Vehicle <- mounted turret

The turret resource code is initially a 3 levels scheme :
Vehicle <- mounted turret <- player mounted on turret

Do you use this 3 level scheme ?
All my work was really easiest after removing 1 level. My first idea was to use the turret object as a player but it crash, so it's why I come back to the standard player code.

In 1st person view my player object is the turret with partial control of the vehicle (a mix of driver and mounted passenger code ripped from various vehicle tutorials). In 3rd view it work like the starter.racing.

... just for sharing point of view ;)
#24
10/14/2004 (12:04 am)
Thanks Pat,a good idea.I only use 2 levels scheme:
Vehicle <- mounted turret
As you say "use the turret object as a player ",Is that will make a turret as a Character?could you post you code?thanks.
#25
10/21/2004 (10:38 pm)
Thanks Pat again!Now I can make the turret as a player,aiming with mouse and control the tank with keyboard at the same time.
#26
12/31/2004 (11:37 am)
I would like to know if this could be applied to a person on a vehicle. If you want to be able to control the vehicle with the keyboard and the persons hand (with a gun in it) with the mouse. Also the camera will be controlled with the mouse. I hear about changeing the control object but I do not understand how this is done in code.
#27
05/11/2005 (3:23 pm)
Ok, I am attempting the "one person controlling the vehicle and turret" and using this example, I am noticing that the turret seems sluggish/choppy.

So I went in a slightly different approach (placed the turret in mount0 and instead of having the vehicle reference the turret, I had the turret reference the vehicle).

Now, the turret moves smoothly but the car refuses to move.

I commented out the call to vehicle->updateMove(move) from within my turret's updateMove() call and added to my turret's processTick() function the line:
if (vehicle) vehicle->processTick(move);

(I also added "if (vehicle) vehicle->interpolateTick(dt);" to Turret::interpolateTick().)

I now get car movement but suddenly the car movement is choppy as heck.

Does anyone have any suggestions to better synce the vehicle/car with the attached turret?

I'll keep working and post my findings if I figure anything out before I get working feedback.
#28
05/23/2005 (3:04 pm)
The Player::onCollsion() method now basically uses this snippit for attaching to the vehicle turret:

-----------------
%node = findEmptySeat(%col, %this);
if(%col.mountedTurret.currentDriver $= "" && %node > 0)
{
warn("FOUND MOUNTED TURRET ON vehicle! %node =" SPC %node);
%col.mountedTurret.mountObject(%obj, 0);
%col.mountedTurret.currentDriver = %client;
%turretMounted = true;
}

%obj.mVehicle = %col;
%camObj = %obj.client.getCameraObject(); // grab the player object
%obj.client.setcontrolobject(%col.mountedTurret); // setting the turret as a control object
%obj.client.setCameraObject(%camObj); // set the player as the camera controller
-----------------

The trick for me was that I had to reset the camera object back to the player (and I'm sure it can be done easier than the way I've done it.) after setting the turret as the control object.
Now, the only jitter I see is from the sitting animation of my character...which is an art issue. :D
#29
05/24/2005 (4:32 am)
I have the same problem with choppy turrets, but I can't use your approach because I have multiple turrets mounted to my vehicle. If I get this right, is it the camera that make the turrets chopp? If so, why?
#30
05/25/2005 (7:41 am)
I solved this problem by using a ShapeBaseImage mounted instead, but that it is controlled by the turret module (that still is mounted but don't have any visible meshes). Our vehicle saves the turret data (rotation) in it self and send that data to the client. Then the client updates it's shapeBaseImage with those values.
#31
08/20/2005 (2:50 am)
I added the turret to a wheeled vehicle (by adding a tYaw and tPitch to the Move Manager), but now the weapon doesn't fire. When I mount the weapon directly on the car, it works, but not when added to the turret. Has anyone else had this problem?
#32
08/20/2005 (3:04 pm)
Are you sure it's getting fire events?
#33
08/20/2005 (4:32 pm)
Its probably not - I think I need to add some code to pass along fire events the same way as the yaw and pitch, but I'm not sure how.

I think I might just punt and build a new turreted vehicle class similar to the Bravetree Tank.
#34
08/20/2005 (5:03 pm)
Hi. I'm trying to get this resource working but it's being a real bitch. Compiling errors everywhere! If it's not too much, could someone host a finished one? This is one of the only resources I've really had trouble with.
#35
09/06/2005 (4:04 pm)
I had the same problem with firing.
First of all i incorporated the code from Tim Dix above to expose the MountedTurret to the client form the server.

Then I had to copy some code from the AITurret to make it work.

first of all in turret.cc

/**
 * Fires a ShapeBaseImage mounted on turret
 */
void Turret::fire( U32 imageSlot )
{
   // fire it
   setImageTriggerState(imageSlot,true);
   setImageTriggerState(imageSlot,false);

}

and a console method

/**
 * Tells the Turret to fire a given ShapeBaseImage
 */
ConsoleMethod( Turret, fire, void, 3, 3, "turret.fire( %slot );" )
{
   Turret *turret = static_cast<Turret *>( object );
   turret->fire( dAtoi(argv[2]) );
}

then in turret.h
in the public section of the Turret class

// firing
   void fire( U32 imageSlot );


Then in your cs file for your vehicle or player or whatever...

function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
   // This method is invoked when the player receives a trigger
   // move event.  The player automatically triggers slot 0 and
   // slot one off of triggers # 0 & 1.  Trigger # 2 is also used
   // as the jump key.
   if (%triggerNum == 0 )
   {
      if(isObject(%obj.mountedTurret))
      {
         %obj.mountedTurret.fire(0);
      }
      else
      {
         echo("No Mounted Turret found");
      }
   }
}

obviously after setting the mounted turret in the first place.

One gotcha that had me going for a while.... Make sure your weapon has ammo if it needs it. I had to put inventry code into my turret cs file, 'cos all my weapons use ammo and the inventory system.

Hope this helps... and I realise it's nothing more than a hack.


Now if someone can tell me how to manually set the angle of this turret using the keyboard or from script, I'd be very happy.
#36
10/09/2005 (4:32 am)
Hi,

Im currently struggling with these same problems as well.

I have implemented the code above and it fires nicely now. But this constuction gives me the following problem:

- A ship has multiple turrets. Each turret has a barral which fires a projectile. Normally, when a player fires the projectile (like the FPS demo) he is the "owner" of the projectile. When it hits something you know which player shot it, and give a score to the one who shot it.

In this case it won't work, since the turret uses the barrel (image) to fire the thingies.

Does anyone have an idea how to solve this?

Thanks in advance!
#37
10/29/2005 (2:45 pm)
I've gotten the turret to fire fine, but when I hit something it dosen't damage it. Also I appear to have infinite ammo
#38
11/01/2005 (1:43 am)
That sounds like a problem with your weapon code... what happens when you mount the weapon onto the player?

Infinite ammo is caused by the weapon not decrimenting the ammo amount on firing.
Damage to the target is inflicted in the weaponProjectile onCollision I think. Look there to see if the damagetype is set up correctly.
#39
11/24/2005 (10:00 am)
I've found a way to modify the move structure so you can control the vehicle and the turret speratley click here
#40
01/04/2006 (11:48 am)
I got my turret mounted to the vehicle, it fires, i can ctrontoll the vehicle with the keyboard, and the turret with the mouse.

But I'm also having the "choppy turret" problem.

Everything runs fine and smooth until i turn the turret.

Anyone got a sollution to this problem?

(I've implemented both the Jason Farmer and Dan Keller code.)