Shooting the Tank?
by NUTS! · in Torque Game Builder · 12/11/2006 (8:16 pm) · 45 replies
I have been trying to figure out how to get the tank to shoot from the TDN tank physics example. This is what my shoot code looks like:
I can get the tank to show up and drive around. However, when I shoot I just get the bullet starting from the center and going to the top, the console error I get is this:
ImageMap(tankChasisImageMap) Error: 'Invalid Bitmap File' (2)
Tanks/gameScripts/PhysTank.cs (24): Register object failed for object tankChassisImageMap of class tdImageMapDatablock.
Which doesn't make any sense why I get that.
My PhysTanks.cs line 4 through 24 looks like :
As you can tell by no means can I script. So any help would be greatly appreciated.
function shoot() {
%tankPosition = turret.getposition();
%mousePosition = sceneWindow2D.getMousePosition();
%shotAngle = t2dAngleBetween(%tankPosition, %mousePosition);
%bullet = new t2dStaticSprite(){ scenegraph = sceneWindow2D.getSceneGraph();};
%bullet.setImageMap ( "ggLogoImageMap" );
%bullet.setSize = "8 8";
%bullet.setLinearVelocityPolar ( $shotAngle, 100); // shoot at speed 100
$nextScheduledShot = schedule(500, 0, "shoot");
}I can get the tank to show up and drive around. However, when I shoot I just get the bullet starting from the center and going to the top, the console error I get is this:
ImageMap(tankChasisImageMap) Error: 'Invalid Bitmap File' (2)
Tanks/gameScripts/PhysTank.cs (24): Register object failed for object tankChassisImageMap of class tdImageMapDatablock.
Which doesn't make any sense why I get that.
My PhysTanks.cs line 4 through 24 looks like :
new t2dImageMapDatablock(tankChassisImageMap) {
canSaveDynamicFields = "1";
imageName = "./images/tankChassis";
imageMode = "FULL";
frameCount = "-1";
filterMode = "SMOOTH";
filterPad = "0";
preferPerf = "0";
cellRowOrder = "1";
cellOffsetX = "0";
cellOffsetY = "0";
cellStrideX = "0";
cellStrideY = "0";
cellCountX = "-1";
cellCountY = "-1";
cellWidth = "0";
cellHeight = "0";
preload = "1";
allowUnload = "0";
defaultConfig = "PhysTankDatablock";
};As you can tell by no means can I script. So any help would be greatly appreciated.
About the author
#42
12/19/2006 (7:45 pm)
@Don, yup works like a charm. I think after reading and researching this a bit that with the newupdates this should be a lot easier. I am going to take a step back and try to redo this. I think a lot more can be placed in TGB. Again, I would like to thank you both so much for your help. I hope I get a chance to repay you someday.
#43
I added in what you mentioned just above and also %cannon.setRotation( turret.getRotation() );
It looks to track perfectly in a straight line out from the barrel when you hit fire.
I have one last silly question.
No matter what I set the size to the shot is still the default image map size, any thoughts? ;)
12/19/2006 (8:03 pm)
Ah ha! You are right on the money again Don! :DI added in what you mentioned just above and also %cannon.setRotation( turret.getRotation() );
It looks to track perfectly in a straight line out from the barrel when you hit fire.
I have one last silly question.
%cannon = new t2dStaticSprite() { scenegraph = sceneWindow2D.getSceneGraph(); };
%cannon.setImageMap( "particles1ImageMap" );
%cannon.setSize = "1 1";No matter what I set the size to the shot is still the default image map size, any thoughts? ;)
#45
this is the oddest thing, that is exactly how the shooter demo has it, but when I try it kicks out a parse error.
I decided to break this off into its own thread so I would not steal away from this thread's topic :-p
here is the link: garagegames.com/mg/forums/result.thread.php?qt=55604
12/20/2006 (6:17 pm)
Hi Phillip,this is the oddest thing, that is exactly how the shooter demo has it, but when I try it kicks out a parse error.
I decided to break this off into its own thread so I would not steal away from this thread's topic :-p
here is the link: garagegames.com/mg/forums/result.thread.php?qt=55604
Torque Owner Don Hogan
If we look back at the system for my turret, you see that I'm using %instigator.getRotation to set the angle and then the speed is a combination of the vehicle's speed and the bullet speed.
Edit: I forgot to say, in this case, instigator is pretty much the same as %this
Let me clarify why we did it this way and how it relates to you. You gave the turret a limited rotation speed and then told it to track the mouse. The mouse will always move faster than the turret, correct? Given that, the bullet pretty much has to get it's rotation from the turret for it to ever look right.
In my optinion this is good. Why? Well, if you want to you can modify the turret's rotation speed simply by changing the variable in script, be it from a pickup or whatever. The good part is that the shoot function is getting that information from the turret datablock, so that same function can potentially be used by all your turrets, friend or foe.
Simply put, whether my datablock is for a Tiger, a Sherman, an Abrahms or a T-72 they can all track the mouse at their own speeds and shoot properly using the same function.
So, keep the turret rotation driven by the mouse, but get the bullet's vector from the turret.