Game Development Community

Using Barrel instead of Eye for Weapon Aiming

by CSMP · in Torque Game Engine · 10/21/2009 (8:12 pm) · 8 replies

I've been looking into trying to replace the center-screen "Eye" aiming with aiming with the weapons MuzzleTransform, theres a couple of places in the ShapeImage.cc that looks like it could be modified for the effect...

for ex. ShapeBase::getRenderImageTransform & ShapeBase::getImageTransform

But I'm not exactly sure how the weapons are pointing the projectile to aim at the center-screen and how to make it fixed to where the barrel is pointing at, I've tried reversing the code Paul /*Ilys*/ gave for the Laser CenterScreen code but it seems that nothing effects the actual aim.

I'm sure I'm overlooking something pretty simple, but I really have no idea how and which piece of code actually affects the projectile aiming.

#1
10/21/2009 (8:47 pm)
www.garagegames.com/community/resources/view/8397]
Have a look at that resource - it does what you're looking for at some point. The changes are mainly in getMuzzleTransform - but I highly reccommend that entire resource. It's great for a tactical FP sort of movement model. Except maybe the most recent update - if you're still using Kork, it makes it impossible to do anything :P.
#2
10/21/2009 (9:21 pm)
Ah, Thanks... Ya I'm setting up the A.C.K. for animation dependant aiming instead of the EyeVector aiming.
#3
10/21/2009 (11:54 pm)
I'll eventually be working on doing something like this, which is animation-dependent aiming to the max ;P. But that's a long way ahead.
#4
10/22/2009 (12:23 am)
Thats actually a really cool feature demo video, lots of ideas can be visualized from that.

BTW: after the Realistic FP Resource it has broken my look angle mounting raycast...

Atm, it is only mounting vehicles that are eye-level instead of where the barrel or eye is looking(either would work) which is making things difficult for some of the vehicles.

Here is the code in question:
function ShapeBase::doRaycast(%this, %range, %mask)
{
   // get the eye vector and eye transform of the player
   %eyeVec   = %this.getEyeVector();
   %eyeTrans = %this.getEyeTransform();

   // extract the position of the player's camera from the eye transform (first 3 words)
   %eyePos = posFromTransform(%eyeTrans);

   // normalize the eye vector
   %nEyeVec = VectorNormalize(%eyeVec);

   // scale (lengthen) the normalized eye vector according to the search range
   %scEyeVec = VectorScale(%nEyeVec, %range);

   // add the scaled & normalized eye vector to the position of the camera
   %eyeEnd = VectorAdd(%eyePos, %scEyeVec);

   // see if anything gets hit
   %searchResult = containerRayCast(%eyePos, %eyeEnd, %mask, %this);

   return %searchResult;
}

I've tried replacing the getEyeTransform with getMuzzleTransform but for some reason it is not recognizing it...
Also made sure to add the current Mountnode into the string.
#5
10/22/2009 (2:15 am)
Interesting... did you implement the whole resource? I didn't think any eye vector stuff was changed, except in the most recent update. However, that code should affect your raycast as well. I'll stick your script into my project and see what I get.

It seems to work for me - I was able to go into Barebones, stand on top of the constructor test interior, look down, cast a ray with the Interior typemask, and detect the interior. I did have to change
%eyePos = posFromTransform(%eyeTrans);
to
%eyePos = getWords(%eyeTrans,0,2);
but I assume you've defined the above function yourself...?

But I don't have the final update in :P. I'll go ahead and add that and see what happens.

EDIT: Haha, silly me. Added the head node moving and I'm seeing the problem you're describing. With a little debugging, it seems that the node transforms are not being set properly. This must be a server-side problem, since the code is obviously working client-side (the camera follows the character's eye node).
So for some reason, the server-side character isn't animating. I thought we fixed that in setActionThread.

Hrm.

EDIT: There's no getMuzzleTransform function - just muzzleVector and muzzlePoint. But those should work for you. Evidently, the muzzle vector is being calculated correctly on the server, since projectiles fly all over the place.
#6
10/22/2009 (3:16 am)
Ya I added Codeblock 1(eye camera fix) and Codeblock 2(Muzzle aim fix), skipped the last codeblock because I already seem to have the effect he describes.

The Raycast function is in the library.cs file (stock MGSK) and called from the MountVehicle function in the serverside command.cs file

Yeah, I'm going to have to go through the 3DGPAI1 book again to brush up on my basic scripting techniques and functions.

That makes sense about the Client/Server sync being the issue, I'm going to test it on a client/server right now and see what else I can find out.
#7
10/22/2009 (5:43 am)
Ok, I found a problem with the install instructions though I have tested it and still no deal... But I'm going to continue this problem in the Resource Thread as that is where it should be at this point.

For any others:(Realistic FirstPerson View) - Recommended W/Advanced Animations
www.garagegames.com/community/resources/view/8397
#8
10/22/2009 (7:11 am)
I seem to have found a solution - but we should continue discussion on the resource thread ;P.