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.
Page«First 1 2 3 Next»
#41
02/15/2006 (8:52 pm)
I have a slight problem getting my turret to fire. I have got my turret mounted on a vehicle, and its rotating properly. When I click the mouse, the fire animation plays (The barrel recoils) but no projectile leaves the barrel. I have successfully implemented all the code changes in this thread, plus the original phDana thread, plus the turrets 1.20 update, and the move manager improvement for mounting turrets to vehicles.
It seems most people here are trying to mount a player character onto a vehicle with a turret on it, but I have done things a little differently in my game. I have the player controlling a flying vehicle object (Spaceship) which I have successfully mounted the turret too.
Could this be the cause of the problem?
When I try mounting the turret as a player in the standard way, it works and fires perfectly.
I am getting no compiler errors, and no errors in my console.
Im sure its somethign simple that I've missed, but ive looked and I cant see where it could be.
When I mount the turret as a player, it calles Shapebase::onfire, which creates and fires a projectile, however when it does not call that function when I try to fire the turret on my ship. Is there something I should add to FlyingVehicleData::onTrigger?
Im not sure why it works as a player but not as an object.
Thanks for any advice,

JS
#42
02/16/2006 (2:23 am)
Jack, I think that the problem you're having is not one of code and triggers, you've mentioned that your weapon's fire animation plays.. this means that it's receiving the fire request.

I would say, check the ammo the *turret* has. As an experiment, try giving the turret a load of ammo.. unless your weapon uses energy.

When the player mounts it, I'm guessing that it's using the player's ammo or energy. I know for sure that energy is inherited from the parent.

If you're getting firing animation playing there should be no reason why a projectile is not coming out.


Add some code to the turret's datablock allowing it to have the same ammo as the player datablock.
Then in the onAdd code where you create your turret, add ammo to it.

I'd give you a script example but I'm not near a Torque PC at the moment.
#43
02/16/2006 (1:42 pm)
Thanks for your reply, it was helpful in pinpointing the problem. I knew I was close when I got that fire animation working, but I still cant get any projectiles.
The turret seems to use energy instead of ammo, because I see a lot of "%obj.setEnergyLevel(%this.MaxEnergy);"
I tried putting the above command in various places, (onAdd, onTrigger) but no go. When you say that its using the player's ammo or energy, I think that might be my problem, since Im not using a player object, im using a flying vehicle.
I tried setting the max energy to a constant value: %obj.setEnergyLevel(100); but it still just plays the animation, and doesnt fire a projectile.
Here is my onTrigger method:

function FlyingVehicleData::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.setEnergyLevel(1000);

			%obj.mountedTurret.fire(0);
			echo(%obj.mountedTurret);
			%obj.setImageTrigger(1, true);

			echo(%obj.getImageState(slot));

			%obj.setImageTrigger(1, true);

		}
		else
		{
			echo("No Mounted Turret found");
		}
	}
}

and my onadd:

function TurretData::onAdd(%this,%obj)
{
    //Parent::onAdd(%this,%obj);
    echo("TurretData::onAdd()");
	%obj.setEnergyLevel(%this.MaxEnergy);
		%obj.setEnergyLevel(1000);
//	%obj.setInventory(HandCannonammo, 30);
    // mount the barrel if one is specified
    if (%this.barrel !$= "")
    {
        echo("TurretData::onAdd() - Mounted Default Barrel on Turret");
	    %obj.mountImage(%this.barrel,%this.barrelSlot);
    }
}

Thanks for any advice,
JS

EDIT: I added this echo to my flyingvehicledata::ontrigger:
echo(%obj.getEnergyLevel());

It says the value is 300, so it has plenty of energy to fire. This value is not decremented when I click the mouse, it just prints 300 again.
Also, I found out that its taking this maxenergy value from my datablock FlyingVehicleData() datablock, not the generic turret one, is that a problem? Should it be reading this value from the turret data block?
#44
02/17/2006 (2:41 am)
OK, you could try setting inheritEnergyFromMount=false in your turret datablock,
that should make it use its own energy supply instead of that of the object it's mounted on.
At the moment it's using energy from the vehicle. Setting the energy level of the turret might do nothing.

In my case, the turret is mounted on the player and weapons use the players energy, this seems to work fine as the player is always charging his energy. You're using a vehicle, I'm not sure about those.

Just try setting this without modifying your current code and see what happens. As you've got your turret being set with energy, then it should work.

If not, there's something else going on.

www.garagegames.com/docs/tge/general/apds03.php Here's the shapeBase datablock definition.

There's a note that inheritEnergyFromMount may be removed in the future. I think this is because it's fairly game specific and not consistent. Ammo doesn't inherit so why should energy?... it should be a coded thing. You want it to inherit, then you should have to tell it what to do... (in my world anyway)
#45
02/17/2006 (9:34 am)
I got it working! I added a smallturretgun::onfire function to generic turret.cs, and it worked perfectly. It was obviously not calling the generic shapebaseimage::onfire, and was looking for a smallturretgun::onfire and didnt find it, so it didnt create a projectile.
Thanks a lot for your help! I learned a lot about how the code actually works now, instead of just copying and pasting and not understanding it.
JS
#46
02/17/2006 (9:51 am)
Excellent.
Glad you got it working. It's always frustrating when things don't seem to be working as they should but always satisfying when you finally crack it. :-)
#47
08/01/2007 (11:50 pm)
I was able to create vehicle but some quries r still there
1.How to mount the player in vehicle?
2.In the file in client/scripts vehiclePassengerMap.cs & vehicleDriverMap.cs what should be written?
3.Actually i want to create hovercraft like thing,which actually can run without any accelration with a minimum speed. and when given accelration it should speed up more than that...
Plz help me regarding to that I m very much novice in torque..
Thanx in advance..
Page«First 1 2 3 Next»