Author Topic: How to make vehicle with rotating guns to driver Z view.  (Read 2356 times)

When you're in a vehicle and use z view to free look. How do i make the rockets in this model to turn to aim at the point where the player is currently looking and limit them to a point where they don't shoot at the vehicle itself.

Also, the rotation would be by the entire cylinder and the angle by the gun body.

Also, the bottom cannon is to be controlled separately, but that really isn't relevant.

« Last Edit: January 24, 2015, 12:04:33 PM by Dannu »

Spawn a projectile at the position %player.getEyePoint(); and send it in the direction of %player.getEyeVector(); if the projectile hits the vehicle itself, spawn the projectile a little forward along the vector.

For obvious reasons, the weapons should rotate visually as well.
I am quite new to making vehicles, so details would be appreciated.

Is the weapon in the players hand? Or is it attached to the actual model?

Check the sketchfab link. It's multiple turrets on a vehicle.

http://puu.sh/eYGdv/69283df01d.png

My bad, I thought you were trying to fire a projectile from a in-hand weapon. Did you give the turrets joints (with names) so you can move them?

Edit: Here's a video showing joints and assigning them (watch at beginning): https://www.youtube.com/watch?v=2fMFpfrE_Vs
« Last Edit: January 24, 2015, 05:46:49 PM by Honorabl3 »

Doesn't really answer my question. Rotating a static object to a point actively is completely beyond me so yeah..

If you're thinking of something like the DV-15 on the Fort Wars server then they are bots mounted to the vehicle, they get the vector of the vehicle/player, as well as azimuth, get the difference, then set the aim location to the bots.

You can just do what Thorfin said. The Vehicle_Tank uses the same concept I think.

You can just do what Thorfin said. The Vehicle_Tank uses the same concept I think.
Nah, that just has the bot mounted to a vehicle concept, not the aiming. However it is a good place to test out getting the turret to turn and fire like you want it to.

So you create a bot without a UIName, have mountpoints on the correct spots, but how do you mount to a specific mountpoint?

Code: [Select]
function TankVehicle::onAdd(%this,%obj)
{
   // Setup the car with some defaults tires & springs
   for(%i = 0; %i < %this.numWheels; %i++)
   {
      %obj.setWheelTire(%i, %this.defaultTire);
      %obj.setWheelSpring(%i, %this.defaultSpring);
   }

   // 4 wheel steering
   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,1);
   %obj.setWheelSteering(2,-0.8);
   %obj.setWheelSteering(3,-0.8);

   // 4 wheel drive
   %obj.setWheelPowered(0,true);
   %obj.setWheelPowered(1,true);
   %obj.setWheelPowered(2,true);
   %obj.setWheelPowered(3,true);

   // turret
   %t = new AIPlayer()
   {
      dataBlock = TankTurretPlayer;
   };
   if(isObject(%t)) //creation can fail due to quota limit
   {
      MissionCleanup.add(%t);
      %obj.mountObject(%t, 2);
      %obj.turret = %t;
      %t.schedule(10,"rigTurret");
   }

   %obj.creationTime = getSimTime();     
}
The //turret comment is what you're specifically looking for. Remember that your bot is in fact a TSShapeConstructor and will need look/root animations.
And also be sure to rig your turret and delete it upon the removal of the vehicle/destruction of the vehicle.
Code: [Select]
function Player::rigTurret(%obj)
{
   if(%obj.dataBlock !$= TankTurretPlayer)
   return;

   if(!isObject(%obj))
   return;

   %parent = %obj.getObjectMount();
   if(!isObject(%parent))
   return;

   %obj.spawnBrick = %parent.spawnBrick;
   %obj.brickGroup = %parent.brickGroup;
}

function TankVehicle::onRemove(%this,%obj)
{
   if(isObject(%obj.turret))
   %obj.turret.delete();
}