Muzzle Points
by genomegames · in Torque 3D Professional · 01/29/2012 (6:11 am) · 9 replies
a character has 2 weapons. the first weapon is mounted on the zero order slot and the second weapon is mounted on the first slot, but when a character fires by the second weapon, bullets escape a muzzle point of the zero-order slot.
I need when a character fires by the first weapon, bullets escape a muzzle point of the zero-order slot and when he fires by the second weapon, bullets escape a muzzle point of the first slot.
Has anyone an answer on this question? Thank you for your time.
I need when a character fires by the first weapon, bullets escape a muzzle point of the zero-order slot and when he fires by the second weapon, bullets escape a muzzle point of the first slot.
Has anyone an answer on this question? Thank you for your time.
About the author
#3
01/30/2012 (12:16 am)
Be aware that the mouseRightFire functionality of a 2nd mounted image (or alt-fire of a single image) will conflict with jetting - if you're using jump jets for the player.
#4
01/30/2012 (12:47 am)
Are you using the getMuzzlePoint/Vector functions? Make sure you're passing the correct slot ID to the functions. This will probably mean modifying your onFire function to determine the slot from the object's data block if it doesn't do so already.
#5
"If your second weapon still fires from the muzzle of the first weapon I would presume you have an error in your "onFire" function which is always getting the location of the "0" slot weapon and not looking to see which slot actually fired."
We link a mount point to a slot, and when a character fires we reference to a number of a slot:
dataBlock = %projectile;
initialVelocity = %initVel;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
Therefore a number of a slot means a mount point number, that's right when a character fires by the first weapon a slot = 0, and when he fires by the second weapon - a slot = 1
01/30/2012 (12:48 am)
I was looking at the end of the A F's post:"If your second weapon still fires from the muzzle of the first weapon I would presume you have an error in your "onFire" function which is always getting the location of the "0" slot weapon and not looking to see which slot actually fired."
We link a mount point to a slot, and when a character fires we reference to a number of a slot:
dataBlock = %projectile;
initialVelocity = %initVel;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
Therefore a number of a slot means a mount point number, that's right when a character fires by the first weapon a slot = 0, and when he fires by the second weapon - a slot = 1
#6
I checked a slot ID, and it's correct
Correction to the first post:
When I fires by the first weapon, bullets escape from a muzzle point 0, when I fires by the second or third weapon, bullets escape from the not exist node - anywhere in space, from the defined point everytime
01/30/2012 (1:03 am)
@DanielI checked a slot ID, and it's correct
Correction to the first post:
When I fires by the first weapon, bullets escape from a muzzle point 0, when I fires by the second or third weapon, bullets escape from the not exist node - anywhere in space, from the defined point everytime
#7
01/30/2012 (5:33 am)
What I would do is just error() all the variables in your onFire function into the console and check the differences when you're firing with weapon 0 and weapon 1. If they all look correct, then it's an error in the source.
#8
I exaggerated where the weapons were mounted and this is what I got:


01/30/2012 (6:20 pm)
I tried it out and I couldn't get a weapon to shoot from its muzzle point.I exaggerated where the weapons were mounted and this is what I got:


#9
getMuzzlePoint seemed to always return a number very close to getEyePoint, but in front and slightly higher. It looked to me like it was acting like the weapon was mounted on the players eyeNode and using the muzzle position from there.
I got rid of the lurker and went to using 2 rocket launchers and it worked fine (nearly).

I would guess the extra variables in the lurkers shapeBaseImageData block, or the arm animations in the model are somehow interfering with the getMuzzlePoint function.
The only problem I did hit was with the Muzzle Vector.
In free camera mode it fired in the correct direction, and in first person camera mode it fired in the correct direction, but in 3rd person camera mode the cameras vector, or one close to it, was used instead of the muzzle vector.
The projectile should be going straight up in this picture, but it is going in the direction of the camera.

[edit] This was with correctMuzzleVector = false;
If I have correctMuzzleVector = true; both the first and third person views fire in the cameras direction, but the free camera still follows the muzzle vector
[edit 2] I looked at the c++ code and found a correctMuzzleVectorTP variable that I hadn't seen before (TP is for Third Person).
If I set correctMuzzleVectorTP = false it does use the weapons muzzle vector in third person view so this isn't a problem.
01/30/2012 (9:17 pm)
I had a further play around to see what is going wrong.getMuzzlePoint seemed to always return a number very close to getEyePoint, but in front and slightly higher. It looked to me like it was acting like the weapon was mounted on the players eyeNode and using the muzzle position from there.
I got rid of the lurker and went to using 2 rocket launchers and it worked fine (nearly).

I would guess the extra variables in the lurkers shapeBaseImageData block, or the arm animations in the model are somehow interfering with the getMuzzlePoint function.
The only problem I did hit was with the Muzzle Vector.
In free camera mode it fired in the correct direction, and in first person camera mode it fired in the correct direction, but in 3rd person camera mode the cameras vector, or one close to it, was used instead of the muzzle vector.
The projectile should be going straight up in this picture, but it is going in the direction of the camera.

[edit] This was with correctMuzzleVector = false;
If I have correctMuzzleVector = true; both the first and third person views fire in the cameras direction, but the free camera still follows the muzzle vector
[edit 2] I looked at the c++ code and found a correctMuzzleVectorTP variable that I hadn't seen before (TP is for Third Person).
If I set correctMuzzleVectorTP = false it does use the weapons muzzle vector in third person view so this isn't a problem.
Torque Owner A F
Default Studio Name
I assume you have figured out most of what I will mention but I will explain it for anyone else who would like to do this.
The first thing you need to do is mount 2 separate weapon images.
The player model will need 2 mount points to be able to do this. You can add extra mount points to a model in the shape editor.
These mount points can be called mount0, mount1, mount2 ... mount10.
Inside the shapeBaseImageData datablocks for your 2 weapons you need to specify which mount point the weapons will use with something like
That means this weapons handle (which is a node called mountPoint inside this weapon model) will be attached to a node called mount0 inside the player model.
To mount this weapon on the player use code like
The "0" in the mountImage function tells it which trigger slot to use, it has nothing to do with mounting the weapon on the players "mount0".
If you mounted this weapon with
it would still be mounted on node "mount0", not "mount1"
To turn on ammunition for this weapon in trigger slot "0" you need something like
Again, the "0" in this function has nothing to do with the node "mount0", it has to do with the "0" used in the mountImage function.
will turn off ammunition for this weapon.
Inside default.bind.cs you have these lines
function mouseFire(%val) { $mvTriggerCount0++; } moveMap.bind( mouse, button0, mouseFire );Which says if mouse button0 (left mouse button) is pressed, make the "0" trigger update its state ($mvTriggerCount0++;).
If there is ammunition this will fire a weapon mounted in slot 0.
you can also make a weapon fire with
Once again, the "0" in this function has nothing to do with "mount0"
Thats all the stuff that already works, now to make a second weapon shoot.
Inside the second weapons shapeBaseImageData datablock you need to specify a different mount position for this weapon with
This will put this weapon in a different position that the first weapon, in this case "mount1".
next you need to actually mount the weapon with
The "1" in this function will place this weapon in trigger slot 1, it has nothing to do with "mount1" mentioned in the datablock.
To turn ammo on
To fire this weapon you can use
or you can modify the code in default.bind.cs to have
function mouseRightFire(%val) { $mvTriggerCount1++; } moveMap.bind( mouse, button1, mouseRightFire );You can only mount a weapon image in trigger slot 0, 1, 2 or 3. These trigger slots are just positions in memory, they are not actual locations on a model.
Mount0, mount1, mount2, mount3, mount4 ... mount10 are the actual positions on the model
If your second weapon still fires from the muzzle of the first weapon I would presume you have an error in your "onFire" function which is always getting the location of the "0" slot weapon and not looking to see which slot actually fired.