Making a boat work.
by Stacy Allcock · in Torque 3D Professional · 03/17/2010 (6:58 am) · 32 replies
Hi
Can anyone help?
I am trying to get a boat to work.
I have my boat on a waterblock. But the water goes through the boat and I cant do anything with it.
I bought TGE a few years ago with the aim to make a game, I bought the 3 books recommended. But never actually got round to doing much with the engine due to work commitments. I now have come back to the idea of making a game, but things have changed, so have now bought T3D Pro. But I am totally stuck. Please can someone give me some pointers.
Kind regards
Stacy
Can anyone help?
I am trying to get a boat to work.
I have my boat on a waterblock. But the water goes through the boat and I cant do anything with it.
I bought TGE a few years ago with the aim to make a game, I bought the 3 books recommended. But never actually got round to doing much with the engine due to work commitments. I now have come back to the idea of making a game, but things have changed, so have now bought T3D Pro. But I am totally stuck. Please can someone give me some pointers.
Kind regards
Stacy
About the author
#2
I guess i'll have to go with an invisible box under the surface of the water, and make the boat a wheeled vehicle with invisible wheels.
I have tried this idea with the buggy in the FPS examble, looks ok.
My question now is how do i put the buggy into my blank project?
I can't seem to get it in right. can only get it in without the wheels on, and can't get in or drive it.
Thanks in advance.
Kind regards
Stacy
03/17/2010 (2:50 pm)
Thank you for your reply Marcus.I guess i'll have to go with an invisible box under the surface of the water, and make the boat a wheeled vehicle with invisible wheels.
I have tried this idea with the buggy in the FPS examble, looks ok.
My question now is how do i put the buggy into my blank project?
I can't seem to get it in right. can only get it in without the wheels on, and can't get in or drive it.
Thanks in advance.
Kind regards
Stacy
#3
03/17/2010 (2:58 pm)
you could also just use one of the watercraft resources, Apply physx to the model for buoyancy and model your boat so the player cannot go below the waterline, its really not that difficult to do just make sure you follow T3Ds new directory structure, the scripting is all the same
#4
As far as keeping it floating in the water, a simple bit of hacky code based on the hover code to apply force to the rigid body if the boat sinks too low into the water should do the trick (you should also disable the existing hover code). You could also theoretically set the object's density appropriately, assuming that didn't get broken in the T3D water switchover.
The final steps, in script, involve giving the vehicle a decent amount of angular auto-correction to keep it from randomly flipping over.
If you wanted to get really fancy, you could do things like add some random bobbing motion or have the vehicle pitch up slightly when applying forward thrust.
To be honest, that still seems easier than trying to get a wheeled vehicle (???) to act like a boat. As far as creating it out of a PhysX object, you're skipping all of the vehicle features like health/energy, mounting control objects, particle effects, weapon mounting, sound effects, etc. when you go this route, and will likely end up needing to recode these features in your new custom class anyway.
The one issue I see with what I've described is that the old Rigid class physics can get a bit shaky when a rigid body sits directly on a surface, as in what would happen if you were to beach your boat. This is less glitchy than it used to be, but still is prone to sinking -- for best results, make your collision mesh fairly rounded. In the long run, the devs have indicated that this physics sim will be replaced with a link to the abstracted (PhysX/Bullet/Whatever else) physics layer.
03/18/2010 (11:38 am)
This is probably a little more complex than what you guys are looking ofr, but I would make a version of the flying vehicle that simply won't allow you to apply thrust unless the vehicle is more than 30% submerged (or whatever % fits the model), then remove the ability to apply 1) any linear thrust forces aside from forward and back, and 2) any vertical (pitch) steering force. Finally, the steering force should scale up based on the current velocity, starting at 0 when the vehicle is stationary.As far as keeping it floating in the water, a simple bit of hacky code based on the hover code to apply force to the rigid body if the boat sinks too low into the water should do the trick (you should also disable the existing hover code). You could also theoretically set the object's density appropriately, assuming that didn't get broken in the T3D water switchover.
The final steps, in script, involve giving the vehicle a decent amount of angular auto-correction to keep it from randomly flipping over.
If you wanted to get really fancy, you could do things like add some random bobbing motion or have the vehicle pitch up slightly when applying forward thrust.
To be honest, that still seems easier than trying to get a wheeled vehicle (???) to act like a boat. As far as creating it out of a PhysX object, you're skipping all of the vehicle features like health/energy, mounting control objects, particle effects, weapon mounting, sound effects, etc. when you go this route, and will likely end up needing to recode these features in your new custom class anyway.
The one issue I see with what I've described is that the old Rigid class physics can get a bit shaky when a rigid body sits directly on a surface, as in what would happen if you were to beach your boat. This is less glitchy than it used to be, but still is prone to sinking -- for best results, make your collision mesh fairly rounded. In the long run, the devs have indicated that this physics sim will be replaced with a link to the abstracted (PhysX/Bullet/Whatever else) physics layer.
#5
03/18/2010 (5:44 pm)
I converted the old boating resource to T3D and TGEA and it works quite well. It was pretty easy to convert; although, the boat supplied is somewhat wonky. The boat sits ontop of the water; although, because of the model design the waves washed into the boat. I will see if I can clean the code somewhat and maybe post an updated resource on it.
#6
I managed to find out the problem with not being able to use the buggy.
I started off with the Empty template.
As soon as i switched over to the full template I was able to start playing with the vehicle.
This is one hell of a learning curve but it is fun playing.
Sean Rice I look forward to your boating resource release.
Kind regards
Stacy
03/19/2010 (2:37 am)
Thanks for all your advice. I managed to find out the problem with not being able to use the buggy.
I started off with the Empty template.
As soon as i switched over to the full template I was able to start playing with the vehicle.
This is one hell of a learning curve but it is fun playing.
Sean Rice I look forward to your boating resource release.
Kind regards
Stacy
#7
03/19/2010 (7:07 pm)
Hmmm... seems that I do not have a valid working boat in T3D... I converted it to TGEA without an issue, but they removed some aspects of the waterblock which the boat used. I can get the C++ code to compile, but the boat falls through the water straight down through the terrain. Is your boat actually floating in T3D?
#8
03/20/2010 (3:57 am)
No my boat is a wheeledvehicle sitting on an invisible box just under the water.
#9
now i'm back... just got the license (binary) after playing with the demo for a while to see how far i could get with the scripting engine...
i don't think you need to do any engine mods to get a boat going... i've managed to get a submarine working based on Item "class"...
i use density property to control bouyancy, and setvelocity() to propel it... so far it seems to be working...
the new water is really neat, eh :)

--Mike
03/27/2010 (5:18 pm)
my story sounds just like the original poster's... looked into TGE a while back for a sub game (got a small mention in Ken Finney's book), but i never got it to materialize... now i'm back... just got the license (binary) after playing with the demo for a while to see how far i could get with the scripting engine...
i don't think you need to do any engine mods to get a boat going... i've managed to get a submarine working based on Item "class"...
i use density property to control bouyancy, and setvelocity() to propel it... so far it seems to be working...
the new water is really neat, eh :)

--Mike
#10
03/29/2010 (12:40 pm)
He had it so that when you enter the interior of or boats you are actually teleported to an interior in another place in the map.
#11

click on the image for a short video
after a lot of cursing and swearing (vector math gives me a headache) i finally got the steering and speed changes to work...
--Mike
03/29/2010 (4:07 pm)
another sub added to the fray... my version of nemo's nautilus... made a lil more realistic than the disney version, closer to what you might've seen in during the us civil war period...
click on the image for a short video
after a lot of cursing and swearing (vector math gives me a headache) i finally got the steering and speed changes to work...
--Mike
#12
03/29/2010 (4:09 pm)
Any chance of a code example? I would love to look this over. The video is nice!
#13
after i load a level, i use the console to add the sub to the level... i also start it moving and turn it via console commands...
basically the sub (or boat) is nothing more than a simple ItemData declaration (this may change later on but for now it's the simplest way for me to get back into the swing of all things torque)
datablock ItemData (Submarine){
ShapeFile="art/shapes/NemoNautilus/NemoNautilus.dts";
mass=100;
friction=1;
density=2;
angle=0;
};
i use the desert scene that came with the demo (which i flooded with a waterplane)... then i open the console exec the script file with the datablock declaration... then type in AddSub() at the console (these functions are part of the script file and are 'compiled' when the script is exec'ed);
function AddSub(){
$Sub1 =new Item() {
datablock=Submarine;
};
MissionCleanUp.Add($Sub1);
$Sub1.SetTransform("445 215 243");
}
(you might wanna set your player to those same coordinates, or someplace close so you can see the sub drop into the scene)
i have the water density of my ocean set to 2, so first thing i have to do is lighten up the sub a bit by entering $Sub1.getDataBlock().density=1.5;
that'll bring it up to the surface... that's how i adjust (or will adjust) bouyancy when i'm ready to actually make this into something)... setting the density to any value less than the density of your ocean to make the sub go up... greater than makes sub go down...
speeding it up is just a matter of getting the forward vector and scaling that for use in setvelocity()...
function MoveSubFwd(){
$fwdVec=$Sub1.getForwardVector();
$fwdVec=vectorScale($fwdVec,14);
$Sub1.setVelocity($fwdVec);
$movefwd=schedule (410,0,"MoveSubFwd");
}
the variables for the schedule lets me stop it by cancelling the schedule...
as you can see, this is all a bit sloppy... but for now this is how i work and debug script for new functionality...
that should get ya goin with a scripted only boat... the rest should be easy enough to figure out...
as soon as i make this a real 'class' with keybinds and cleaned up code, i'll make it available to everyone... (though someone here will probably come up with a cleaned up bit of code and a decent boat loong before i do :) )
--Mike
03/29/2010 (4:35 pm)
sure... the code is pretty much in a mess right now... this is an early stage wip... after i load a level, i use the console to add the sub to the level... i also start it moving and turn it via console commands...
basically the sub (or boat) is nothing more than a simple ItemData declaration (this may change later on but for now it's the simplest way for me to get back into the swing of all things torque)
datablock ItemData (Submarine){
ShapeFile="art/shapes/NemoNautilus/NemoNautilus.dts";
mass=100;
friction=1;
density=2;
angle=0;
};
i use the desert scene that came with the demo (which i flooded with a waterplane)... then i open the console exec the script file with the datablock declaration... then type in AddSub() at the console (these functions are part of the script file and are 'compiled' when the script is exec'ed);
function AddSub(){
$Sub1 =new Item() {
datablock=Submarine;
};
MissionCleanUp.Add($Sub1);
$Sub1.SetTransform("445 215 243");
}
(you might wanna set your player to those same coordinates, or someplace close so you can see the sub drop into the scene)
i have the water density of my ocean set to 2, so first thing i have to do is lighten up the sub a bit by entering $Sub1.getDataBlock().density=1.5;
that'll bring it up to the surface... that's how i adjust (or will adjust) bouyancy when i'm ready to actually make this into something)... setting the density to any value less than the density of your ocean to make the sub go up... greater than makes sub go down...
speeding it up is just a matter of getting the forward vector and scaling that for use in setvelocity()...
function MoveSubFwd(){
$fwdVec=$Sub1.getForwardVector();
$fwdVec=vectorScale($fwdVec,14);
$Sub1.setVelocity($fwdVec);
$movefwd=schedule (410,0,"MoveSubFwd");
}
the variables for the schedule lets me stop it by cancelling the schedule...
as you can see, this is all a bit sloppy... but for now this is how i work and debug script for new functionality...
that should get ya goin with a scripted only boat... the rest should be easy enough to figure out...
as soon as i make this a real 'class' with keybinds and cleaned up code, i'll make it available to everyone... (though someone here will probably come up with a cleaned up bit of code and a decent boat loong before i do :) )
--Mike
#14
03/29/2010 (4:40 pm)
Nice vid! That is really quite cool. :)
#15
just getting started :)
we finally have a decent ocean plane/waterblock to work with... the new Torque looks like the one i've been waiting for...
--Mike
03/29/2010 (4:44 pm)
thx Steve...just getting started :)
we finally have a decent ocean plane/waterblock to work with... the new Torque looks like the one i've been waiting for...
--Mike
#16
I initialize these to be somewhere in front of the submarine and modify the yaw based on the rudder angle and current speed, and modify the z aim and destination based on submarine trim (the pitch) - operated by the user through adjustment of forward and rear compensating ballast and hydroplanes.
Implementing the main ballast was a bit of a cheat - as this affects the depth without the motor running. If the motor is on - the main ballast is factored into the heading based on trim, otherwise I just schedule a constant update in the z-coordinate of the sub based on the current value and where the main ballast would take it.
The main problem with using AIPlayer is that pitch and roll for the model are not allowed by the engine, so might try using ItemData (other suggestions include the flying vehicle) - I have started on a workaround to do the pitch as an animation. It kind of works - I keyframe 5 degree intervals and switch between the animations based on the current trim, but the switching is pretty jerky - and the anims don’t play at all when the sub is moving.
03/29/2010 (5:46 pm)
Thanks for the info Mike. To add to the 'submariners convention' - I have done something similar, but based on the AIPlayer datablock using setAimLocation and setMoveDestination.I initialize these to be somewhere in front of the submarine and modify the yaw based on the rudder angle and current speed, and modify the z aim and destination based on submarine trim (the pitch) - operated by the user through adjustment of forward and rear compensating ballast and hydroplanes.
Implementing the main ballast was a bit of a cheat - as this affects the depth without the motor running. If the motor is on - the main ballast is factored into the heading based on trim, otherwise I just schedule a constant update in the z-coordinate of the sub based on the current value and where the main ballast would take it.
The main problem with using AIPlayer is that pitch and roll for the model are not allowed by the engine, so might try using ItemData (other suggestions include the flying vehicle) - I have started on a workaround to do the pitch as an animation. It kind of works - I keyframe 5 degree intervals and switch between the animations based on the current trim, but the switching is pretty jerky - and the anims don’t play at all when the sub is moving.
#17
i kinda like your solution... i mean your using the ai player as a base 'class', and your using the setAimLocation() and setDestination() functions... those may come in usefull for me as well once i get to the stage where i'll be needing enemy subs and torpedo tracks...
as far as ballasting goes... in my sub i allow the ballast to be changed regardless of whether the sub is in motion or not (for vertical surfacing through the ice)... but you are right as far as the pitch (deck angle) affecting the diving... i am going to have to work out a alogorithm that'll allow me to both change the sub angle, plus factor in the sub's deck angle and speed in order to get something close to a realistic dive...
right now i'm testing a simple steering algorithm that's based on multiplying the matrices of both the exisiting orientation and the desired changed orientation...
it's not by any means bulletproof, and it's still in a crude state right now (to change course i call this function from the console and supply the desired course change in radians), but it's very simple (for me, simple is the always the best way to go) you should be able to see what it's doing...
function turnSub(%desired)
{
%rotation1 = GetWords($Sub1.getTransform(),3,6);
%rotation2 = "0 0 1 " SPC %desired;
%v1 = "0 0 0" SPC %rotation1;
%v2 = "0 0 0" SPC %rotation2;
%v3 = MatrixMultiply(%v1,%v2);
$newTransform = getWords($Sub1.getTransform(),0,2) SPC GetWords(%v3,3,6);
$Sub1.setTransform($newTransform);
}
(the logic was pilferred and adapted from the generous help originally given by community members... big thx)
to turn the sub to the right i simply call turnSub(0.1); (actually, i guess turnSub(mDegToRad(2)); might be more correct way of doing it)
please forgive the use of globals and the disorganized state the code is in right now... while implementing new logic i find that editing the script, execing it while the app is running, and calling the functions works well and gives immediate feedback... i'll clean this up eventually and make it a true 'class', but in the meantime bear with me here...
any input appreciated... and if you find the turnSub() logic usefull, testing and trying to find any faults in it would be most helpfull...
thx
--Mike
03/30/2010 (2:50 am)
a sub convention... hey, that sounds like a good idea Martin... exactly what we need around here :)i kinda like your solution... i mean your using the ai player as a base 'class', and your using the setAimLocation() and setDestination() functions... those may come in usefull for me as well once i get to the stage where i'll be needing enemy subs and torpedo tracks...
as far as ballasting goes... in my sub i allow the ballast to be changed regardless of whether the sub is in motion or not (for vertical surfacing through the ice)... but you are right as far as the pitch (deck angle) affecting the diving... i am going to have to work out a alogorithm that'll allow me to both change the sub angle, plus factor in the sub's deck angle and speed in order to get something close to a realistic dive...
right now i'm testing a simple steering algorithm that's based on multiplying the matrices of both the exisiting orientation and the desired changed orientation...
it's not by any means bulletproof, and it's still in a crude state right now (to change course i call this function from the console and supply the desired course change in radians), but it's very simple (for me, simple is the always the best way to go) you should be able to see what it's doing...
function turnSub(%desired)
{
%rotation1 = GetWords($Sub1.getTransform(),3,6);
%rotation2 = "0 0 1 " SPC %desired;
%v1 = "0 0 0" SPC %rotation1;
%v2 = "0 0 0" SPC %rotation2;
%v3 = MatrixMultiply(%v1,%v2);
$newTransform = getWords($Sub1.getTransform(),0,2) SPC GetWords(%v3,3,6);
$Sub1.setTransform($newTransform);
}
(the logic was pilferred and adapted from the generous help originally given by community members... big thx)
to turn the sub to the right i simply call turnSub(0.1); (actually, i guess turnSub(mDegToRad(2)); might be more correct way of doing it)
please forgive the use of globals and the disorganized state the code is in right now... while implementing new logic i find that editing the script, execing it while the app is running, and calling the functions works well and gives immediate feedback... i'll clean this up eventually and make it a true 'class', but in the meantime bear with me here...
any input appreciated... and if you find the turnSub() logic usefull, testing and trying to find any faults in it would be most helpfull...
thx
--Mike
#18
03/30/2010 (5:20 am)
Oh, thanks Michael, I asked for a sample and you hooked us up!
#20
it seems that yawing left or right is no problem... but trying to simulate a dive angle by tilting the thing downward or up is beyond me...
i'd also like to be able to add a lil roll so that it seems like a real boat, but i'd be happy just to get it to tilt in a direction for now...
can anyone point me in the right direction...
thx in advance...
--Mike
04/06/2010 (3:53 pm)
ok... now i can use a lil help with this boat thing... no matter what i try, i can't get this thing to tilt (pitch) up or down... it seems that yawing left or right is no problem... but trying to simulate a dive angle by tilting the thing downward or up is beyond me...
i'd also like to be able to add a lil roll so that it seems like a real boat, but i'd be happy just to get it to tilt in a direction for now...
can anyone point me in the right direction...
thx in advance...
--Mike
Torque 3D Owner Marcus L