Need clarification on correctMuzzleVector/eyeOffset ...
by elvince · in Torque 3D Professional · 10/11/2010 (7:04 am) · 5 replies
HI all,
I was wondering yesterday why my gun was not firing at my crosshair.
I look in scripts and I missed the eyeOffset parameter.
I set it as the rocket launcher and this worked great.
Now I would like to understand exactly how those 4 parameter are working:
Thinks where I need help:
1/ eyeOffset, is it a vector from the eye node of the model to the muzzle node? Is it from a virtual eye node (I mean something like 90% of the total size of the model and center horizontally)? Is it to another node than muzzle point?
2/ correctMuzzleVector / firstPerson seems to be tightly link. So if I set them both to true, I don't need to calculate my eyeOffset/rotation and the program will do it, is it correct? What will happen in all other case (true/false, false/true).
if you see some other useful information on this, don't hesitate.
Thanks,
I was wondering yesterday why my gun was not firing at my crosshair.
I look in scripts and I missed the eyeOffset parameter.
I set it as the rocket launcher and this worked great.
Now I would like to understand exactly how those 4 parameter are working:
addField( "eyeOffset", TypeMatrixPosition, Offset(eyeOffset, ShapeBaseImageData),
"\"X Y Z\" translation offset from the ShapeBase model's eye node.\n"
"Only affects 1st person POV." );
addField( "eyeRotation", TypeMatrixRotation, Offset(eyeOffset, ShapeBaseImageData),
"\"X Y Z ANGLE\" rotation offset from the ShapeBase model's eye node.\n"
"Only affects 1st person POV." );
addField( "correctMuzzleVector", TypeBool, Offset(correctMuzzleVector, ShapeBaseImageData),
"Flag to adjust the aiming vector to the eye's LOS point.\n\n"
"@see getMuzzleVector" );
addField( "firstPerson", TypeBool, Offset(firstPerson, ShapeBaseImageData),
"This flag must be set for the adjusted LOS muzzle vector to be computed.\n\n"
"@see getMuzzleVector" );Thinks where I need help:
1/ eyeOffset, is it a vector from the eye node of the model to the muzzle node? Is it from a virtual eye node (I mean something like 90% of the total size of the model and center horizontally)? Is it to another node than muzzle point?
2/ correctMuzzleVector / firstPerson seems to be tightly link. So if I set them both to true, I don't need to calculate my eyeOffset/rotation and the program will do it, is it correct? What will happen in all other case (true/false, false/true).
if you see some other useful information on this, don't hesitate.
Thanks,
About the author
Recent Threads
#2
With eyeoffset I remember having a issue when looking at my foot. You will see you arms without the weapon wich is quite confusing.
I think I won't set the eyeoffset and use the correct muzzlevector option.
Just to be sure I understand properly, the correct vector will match the eye vector at the first object in sight. So localized damage will work. Correct?
If I m in 3rd person the Getmuzzle vector will never take into account the eyeoffset and will always match the eyevector target as first person correctes muzzle vector. Correct?
Thanks,
10/11/2010 (10:56 am)
That the kinss of wording I ll like to have in the docs. With eyeoffset I remember having a issue when looking at my foot. You will see you arms without the weapon wich is quite confusing.
I think I won't set the eyeoffset and use the correct muzzlevector option.
Just to be sure I understand properly, the correct vector will match the eye vector at the first object in sight. So localized damage will work. Correct?
If I m in 3rd person the Getmuzzle vector will never take into account the eyeoffset and will always match the eyevector target as first person correctes muzzle vector. Correct?
Thanks,
#3

Here's a quick diagram which shows what correctMuzzleVector does better than I can describe it. The light blue line is the path the projectile would follow, gray line is the line of sight.
If you're not setting eyeOffset at all then your 1st and 3rd person weapon position and angle will be identical, it's only your point of view that changes. The stock 3rd person camera for the Player Class is actually just pulled straight back along the line of sight (that's why it's always aiming at your Player's head) so 1st/3rd person view shouldn't make any difference here either (and it will ignore the back or your Player's head when doing the line of sight raycast).
I should warn you that technically the code looks like it intends to disable correctMuzzleVector when in 3rd person, but it definitely still works -- at least in Beta 2, haven't tried it in B3 (try holding V in 3rd person, moving the mouse to look around and then firing, you'll see that you can actually fire sideways or even behind your Player if correctMuzzleVector is true).
The check which is supposed to confirm 3rd person is done in the function void ShapeBase::getMuzzleVector(U32 imageSlot,VectorF* vec) in shapeImage.cpp, "if (gc->isFirstPerson()..." It must always be returning true right now or else it would never make it to calling getCorrectedAim.
10/11/2010 (1:15 pm)
As far as seeing the Player's feet/hands, generally if you're using eyeOffset you'd want to turn the rendering of the Player model in first person off (renderFirstPerson = false; in the Player Datablock) and add some arms to a special LOD of the weapon only for first person view. Sounds like you're going to use the first person view of the full Player model method instead, but just in case you want to know here is a post that describes how to create a unique 1st person weapon LOD. Anyway...
Here's a quick diagram which shows what correctMuzzleVector does better than I can describe it. The light blue line is the path the projectile would follow, gray line is the line of sight.
If you're not setting eyeOffset at all then your 1st and 3rd person weapon position and angle will be identical, it's only your point of view that changes. The stock 3rd person camera for the Player Class is actually just pulled straight back along the line of sight (that's why it's always aiming at your Player's head) so 1st/3rd person view shouldn't make any difference here either (and it will ignore the back or your Player's head when doing the line of sight raycast).
I should warn you that technically the code looks like it intends to disable correctMuzzleVector when in 3rd person, but it definitely still works -- at least in Beta 2, haven't tried it in B3 (try holding V in 3rd person, moving the mouse to look around and then firing, you'll see that you can actually fire sideways or even behind your Player if correctMuzzleVector is true).
The check which is supposed to confirm 3rd person is done in the function void ShapeBase::getMuzzleVector(U32 imageSlot,VectorF* vec) in shapeImage.cpp, "if (gc->isFirstPerson()..." It must always be returning true right now or else it would never make it to calling getCorrectedAim.
#4
I just did some test in Beta 3:
EyeOffset on & CorrectMuzzle off = Working for 1st & 3rd
Eyeoffset off & CorrectMuzzle off = firing in // of lOS (expected)
Eyeoffset off & CorrectMuzzle on = 1st working 3rd // LOS (not expected)
EyeOffset on & CorrectMuzzle on = Working for 1st & 3rd
I will look in the C++ source to understand why the CorrectMuzzle do not do its job in 3rd person view. (maybe a bug?)
Ps: I'm in Beta 3
10/11/2010 (5:34 pm)
thanks for those useful information.I just did some test in Beta 3:
EyeOffset on & CorrectMuzzle off = Working for 1st & 3rd
Eyeoffset off & CorrectMuzzle off = firing in // of lOS (expected)
Eyeoffset off & CorrectMuzzle on = 1st working 3rd // LOS (not expected)
EyeOffset on & CorrectMuzzle on = Working for 1st & 3rd
I will look in the C++ source to understand why the CorrectMuzzle do not do its job in 3rd person view. (maybe a bug?)
Ps: I'm in Beta 3
#5
I debug and the value isFirstPerson is working as intended.
I raise this as a bug, as this features is causing confusion.
More on 3rd view, you can have the mountOffset that may interact in weapon position, so the EyeOffset may be not enough to adjust your aim (I need to look deeply for this).
The EyeOffset is affecting the 3rd view because the isFirstPerson is true in getImageTransform when firing.
10/12/2010 (6:30 am)
I don't know if it was intended, but the getmuzzle vector test gc->isFirstPerson()before calculating the corrected aim.I debug and the value isFirstPerson is working as intended.
I raise this as a bug, as this features is causing confusion.
More on 3rd view, you can have the mountOffset that may interact in weapon position, so the EyeOffset may be not enough to adjust your aim (I need to look deeply for this).
The EyeOffset is affecting the 3rd view because the isFirstPerson is true in getImageTransform when firing.
Torque Owner Henry Todd
Atomic Walrus
Generally, to make the weapon look correct in traditional FPS terms it will be to the right of and below the first person camera, but pointing directly ahead (eyeRotation of "0 0 0"). Having the zero rotation will also make sure the weapon fires straight ahead, however because of the offset it will fire its projectiles slightly below and to the right of your crosshair (but still parallel to your line of sight). At close range the offset will be noticable, however at very long range it will not. I wouldn't recommend trying to use the eyeRotation to aim the weapon, as this will only result in aiming it to converge with the line of sight at some specific distance. If you want to make the weapon trajectory match the line of sight exactly without using correctMuzzleVector you would need to adjust the weapon such that the muzzlePoint node was exactly at the center of your screen. In theory you could alter the location of the muzzlePoint node in the weapon model to be above and to the left of the weapon geometry, allowing you to place the weapon at a "normal" offset while having the projectile fire directly from the location of the first person camera.
correctMuzzleVector will cause the weapon to always fire its projectile in whatever direction the Player is looking regardless of the orientation of the weapon. It performs a raycast to 500m and will adjust the vector returned by getMuzzleVector so that projectiles fired from the weapon's muzzlePoint node, wherever it is, will hit whatever is directly in your line of sight. If the raycast does not strike anything, getMuzzleVector will return a vector that causes the projectile to cross the line of sight at a distance of 500m. If you want to adjust the raycast range it's defined in ShapeBase::getCorrectedAim in shapeImage.cpp. The line is "const F32 maxAdjD = 500;"
The value "firstPerson" does not appear to be used anywhere in the code even though it's referenced in the comments, and either way it's set to true by default.
Just to throw out an alternative, you can alter the fire script in scripts/server/weapon.cs to create the projectile at any point. The only way to have absolutely perfect aim would be to alter this script to use initialPosition = %obj.getEyePoint(); So long as your weapon has an eyeOffset defined (so that it's not moving around from the Player's animations) and eyeRotation is set to "0 0 0" the projectile should now fire directly from the first person camera in whatever direction you are looking. The only disadvantage is that, if your projectile has a fairly distinct trail like a rocket's smoke trail, it will very clearly have come from your Player's head.