Projectiles won't fly straight
by Patrick Webber · in Torque 3D Professional · 09/19/2013 (1:54 pm) · 20 replies
Hi all,
I've imported a custom model, made with Blender, in a clean build of the engine. I'm trying to implement a bow and I've gotten it (mostly) working. You can pull it back longer for more range, and its animated nicely.
Here's the problem though. My projectiles go off like nonsense when I fire. This isn't related to the built-in random accuracy value, this is completely off.
I tried using a standard gun, and the same issue appeared. Interestingly, I also tried the bow with the default player model (the soldier) and it worked perfectly.
So it seems to be related to my model...I'm not sure whats off though. I did notice that the projectiles will be further off base when looking up or down. Whether the projectile is off to the left or right of the aimer, depends on the direction I'm facing. It seems like some sort of vector offset isn't being correctly applied (like its not relative to the player or something?)
I also know this isn't related to only my custom model (I've also tried playing as a standard cube with the same issue), so it may be blender related (but I have no idea why!)
Any ideas? I've started looking through engine source to find out where its messing up now, seriously in need of some guidance.
Thanks,
Patrick
Edit: Video of the problem
I've imported a custom model, made with Blender, in a clean build of the engine. I'm trying to implement a bow and I've gotten it (mostly) working. You can pull it back longer for more range, and its animated nicely.
Here's the problem though. My projectiles go off like nonsense when I fire. This isn't related to the built-in random accuracy value, this is completely off.
I tried using a standard gun, and the same issue appeared. Interestingly, I also tried the bow with the default player model (the soldier) and it worked perfectly.
So it seems to be related to my model...I'm not sure whats off though. I did notice that the projectiles will be further off base when looking up or down. Whether the projectile is off to the left or right of the aimer, depends on the direction I'm facing. It seems like some sort of vector offset isn't being correctly applied (like its not relative to the player or something?)
I also know this isn't related to only my custom model (I've also tried playing as a standard cube with the same issue), so it may be blender related (but I have no idea why!)
Any ideas? I've started looking through engine source to find out where its messing up now, seriously in need of some guidance.
Thanks,
Patrick
Edit: Video of the problem
About the author
I'm a computer science major at Stony Brook University, and have been working with the Torque Game Engine for a number of years.
#2
Both the model and the weapon have the nodes setup properly.
Actually, I've rewritten the onFire method for my bow, and changed the projectiles to come out of the head, and use the direction I'm looking as the movement.
Like I said though, the bow, and the standard rifle (the Lurker) will shoot and miss the aimer.
09/19/2013 (3:04 pm)
Hi Robert,Both the model and the weapon have the nodes setup properly.
Actually, I've rewritten the onFire method for my bow, and changed the projectiles to come out of the head, and use the direction I'm looking as the movement.
Like I said though, the bow, and the standard rifle (the Lurker) will shoot and miss the aimer.
#3
09/19/2013 (3:23 pm)
Without seeing the code (hence the math for your vector) it will be hard to tell what is going on.
#4
and the Lurker code is the standard. Note, I've tried a couple different means of positioning it in front of the player (I've gotten stuff to fly straight before with a spell system I implemented)
09/19/2013 (3:27 pm)
Sure, here's the custom code for my bow right now:%multiplier = %obj.bowStrength;
%muzzleVector = %obj.getEyeVector();
%numProjectiles = %this.projectileNum;
if (%numProjectiles == 0)
%numProjectiles = 1;
for (%i = 0; %i < %numProjectiles; %i++)
{
%muzzleVelocity = VectorScale(%muzzleVector, 5 * (%multiplier) + 1);
%positionOfArrow = VectorScale(%obj.getEyeVector(), 2);
%positionOfArrow = VectorAdd(%positionOfArrow, %obj.getPosition());
%positionOfArrow = VectorAdd(%positionOfArrow, "0 0 2");
// Create the projectile object
%p = new (%this.projectileType)()
{
dataBlock = "arrow";
initialVelocity = %muzzleVelocity;
initialPosition = %positionOfArrow;
client = %obj.client;
sourceClass = %obj.getClassName();
};
MissionCleanup.add(%p);
}and the Lurker code is the standard. Note, I've tried a couple different means of positioning it in front of the player (I've gotten stuff to fly straight before with a spell system I implemented)
#5
Or is this related to a datablock setting?
I cannot see anything off in your code. I can see why this is confusing.
09/19/2013 (5:24 pm)
Okay, so this works with the regular solider model and not the custom models? So something is telling the vector to be off by some number of degrees? Like 90 degrees? Or is this related to a datablock setting?
I cannot see anything off in your code. I can see why this is confusing.
#6
09/19/2013 (5:33 pm)
I'd recommend swapping out "%muzzleVector = %obj.getEyeVector();" with "%muzzleVector = %obj.getMuzzleVector(%slot);".
#7
It seems to be off by an amount which changes based off of the direction I am looking (and how up/down I am looking), so if something is telling the vector to be off, is seems routed in where I'm looking... If this was a datablock thing, any setting you can think off to tweak? I've messed with them quite a bit.
@Robert
I have had that in the past, I had changed it to my eye vector in attempt to fix it, to no avail. I can put that back though.
09/19/2013 (7:03 pm)
@DemolishunIt seems to be off by an amount which changes based off of the direction I am looking (and how up/down I am looking), so if something is telling the vector to be off, is seems routed in where I'm looking... If this was a datablock thing, any setting you can think off to tweak? I've messed with them quite a bit.
@Robert
I have had that in the past, I had changed it to my eye vector in attempt to fix it, to no avail. I can put that back though.
#8
09/19/2013 (7:49 pm)
Well, I'm just placing that there because it sounded like a potential rotation error of your model's EYE node.
#9
09/20/2013 (4:52 pm)
That's a good point, I've changed it back now. They still fly with a broken offset, so I'm guessing there's something wrong with the eye node, like you said. I can't think of whats up with it. It does use an eye node that my modeler labeled as eye (Torque automatically assigned it correctly), but I thought I read somewhere that the eye node ignores rotation...
#10
I don't know that it is that important for the projectile to come from the weapon. I would think that it was more important that the projectile hit its target. If the camera is mounted to the eye node it should come from the eye node, but the vector should be from the camera. I am not sure how this would look third person, but I think you could fudge it enough to not matter.
09/20/2013 (7:02 pm)
Shouldn't the camera vector be what you would use to send a projectile?I don't know that it is that important for the projectile to come from the weapon. I would think that it was more important that the projectile hit its target. If the camera is mounted to the eye node it should come from the eye node, but the vector should be from the camera. I am not sure how this would look third person, but I think you could fudge it enough to not matter.
#11
I'm the temporary modeler that's been working with Patrick thus far. I'm not sure why the issues are occurring, but I do agree that evidence definitely points towards the model being at fault. I'm not a real artist to any degree, and the model is definitely a 'test' model- but at the same time I really can't tell what the issue is. I've looked and looked and even fixed a couple things that I thought might be the cause, but nothing has done the job, so I figured I'd upload the blend and hope for the best.
speedy.sh/q65U2/patterfred.blend
Thanks, guys. You make the T3D community awesome :D
09/24/2013 (9:15 am)
Hey guys,I'm the temporary modeler that's been working with Patrick thus far. I'm not sure why the issues are occurring, but I do agree that evidence definitely points towards the model being at fault. I'm not a real artist to any degree, and the model is definitely a 'test' model- but at the same time I really can't tell what the issue is. I've looked and looked and even fixed a couple things that I thought might be the cause, but nothing has done the job, so I figured I'd upload the blend and hope for the best.
speedy.sh/q65U2/patterfred.blend
Thanks, guys. You make the T3D community awesome :D
#12
you have:
which is the location you are starting the projectile at. This will change based on the Pitch of the characters head, if there is an eye node in it.
Personally I would just use what Robert suggested.
To see where the problem is I would put a break point on this line and look at the value inside %positionOfArrow.
If you don't have torsion, after the MissionCleanup.add(%p); line add:
This will put the starting direction as grey text in the console, and the starting position as cyan text, and the eye position in red.
Have a look in the console after you shoot and look at these values, this should give you an idea of what has went wrong.
09/24/2013 (10:04 pm)
Like everyone else has said you should change the starting positionyou have:
%positionOfArrow = VectorScale(%obj.getEyeVector(), 2);
%positionOfArrow = VectorAdd(%positionOfArrow, %obj.getPosition());
%positionOfArrow = VectorAdd(%positionOfArrow, "0 0 2");which is the location you are starting the projectile at. This will change based on the Pitch of the characters head, if there is an eye node in it.
Personally I would just use what Robert suggested.
%positionOfArrow = %obj.getMuzzlePoint(%slot);
To see where the problem is I would put a break point on this line and look at the value inside %positionOfArrow.
If you don't have torsion, after the MissionCleanup.add(%p); line add:
echo(%muzzleVelocity); warn(%positionOfArrow); error(%obj.getEyePoint();
This will put the starting direction as grey text in the console, and the starting position as cyan text, and the eye position in red.
Have a look in the console after you shoot and look at these values, this should give you an idea of what has went wrong.
#13
See scripts/server/weapon.cs in WeaponImage::onFire() to see how the game is setting it all up for basic projectiles.
09/25/2013 (1:27 pm)
Bow has a muzzle node defined in the model? Muzzle node is oriented in the correct direction?See scripts/server/weapon.cs in WeaponImage::onFire() to see how the game is setting it all up for basic projectiles.
#14
@A F
I've set the position of the arrow to the muzzle point and had it print out the values. I can't really make much sense of them, but the bow might be looking a bit better now.
@Richard
The bow had all of its nodes defined, and I think that the muzzle node is in the correct direction. I have looked at the WeaponImage::onFire() code, its actually where I started for this (originally I just ripped code from there).
I finally got around to recording the two players (my model "fred" and the default model) using the bow. You can check out the video here.
09/25/2013 (3:14 pm)
Hey guys, thanks for the replies.@A F
I've set the position of the arrow to the muzzle point and had it print out the values. I can't really make much sense of them, but the bow might be looking a bit better now.
@Richard
The bow had all of its nodes defined, and I think that the muzzle node is in the correct direction. I have looked at the WeaponImage::onFire() code, its actually where I started for this (originally I just ripped code from there).
I finally got around to recording the two players (my model "fred" and the default model) using the bow. You can check out the video here.
#15
I stripped out the animations from the model.
I stopped using the bow (switched over to the lurker).
I also have tried a clean import of the model numerous times.
I made it so the mount points won't swing with the arms (unparented them).
All of which didn't change anything...
Again, all weapons work 100% with the soldier_rigged model.
Thanks for your help.
09/26/2013 (9:17 pm)
Just thought I'd mention a couple more things I've tried...I stripped out the animations from the model.
I stopped using the bow (switched over to the lurker).
I also have tried a clean import of the model numerous times.
I made it so the mount points won't swing with the arms (unparented them).
All of which didn't change anything...
Again, all weapons work 100% with the soldier_rigged model.
Thanks for your help.
#16
09/27/2013 (12:11 pm)
Personally, i think it is a bad idea to use the model for any kind of vector/position sources for projectiles. This creates an unnecessary burden on the artist to ensure the game play will work properly. That is why I suggested using information from the camera. You know the vector will be correct and you can use the position of the camera.
#17
I've got a version of the weapon that uses those on fire as well, and I still have the same issue.
If your talking about something else though, please let me know.
Thanks.
09/27/2013 (2:09 pm)
Your talking about Player.getEyePoint() and Player.getEyeVector() right? I've got a version of the weapon that uses those on fire as well, and I still have the same issue.
%muzzleVector = %obj.getEyeVector();//getMuzzleVector(%slot);
%numProjectiles = %this.projectileNum;
if (%numProjectiles == 0)
%numProjectiles = 1;
for (%i = 0; %i < %numProjectiles; %i++)
{
%muzzleVelocity = VectorScale(%muzzleVector, 5 * (%multiplier) + 1);
%positionOfArrow = %obj.getEyePoint();//.getMuzzlePoint(%slot);
// Create the projectile object
%p = new (%this.projectileType)()
{
dataBlock = "arrow";
initialVelocity = %muzzleVelocity;
initialPosition = %positionOfArrow;
client = %obj.client;
sourceClass = %obj.getClassName();
};
MissionCleanup.add(%p);
echo(%muzzleVelocity);
warn(%positionOfArrow);
error(%obj.getEyePoint());
}I checked that this code is fired with a break point as well. The models nodes aren't rotated off in Blender or the shape editor.If your talking about something else though, please let me know.
Thanks.
#18
I cleaned out my whole torque install, installed a fresh one, re-exported a dae, re-imported the dae into torque, remapped all animations, reset all the datablocks, and that seems to have fixed it. I was hoping to avoid doing all this, I'm still not sure what broke it in the first place...
Anyway, thanks to everyone for your help!
-Patrick
09/27/2013 (2:24 pm)
Well, I don't know what had happened, but I'll post what I did here for anyone else with this issue.I cleaned out my whole torque install, installed a fresh one, re-exported a dae, re-imported the dae into torque, remapped all animations, reset all the datablocks, and that seems to have fixed it. I was hoping to avoid doing all this, I'm still not sure what broke it in the first place...
Anyway, thanks to everyone for your help!
-Patrick
#20
09/28/2013 (10:14 am)
Wait, is it possible you did not select "reload DAE file" while you were debugging your model?
Torque Owner Robert Fritzen
Phantom Games Development