I have a node (the tank in the foreground of the screen shot) that I would like to rotate the pitch relative to the landscape. You can see the obvious problem in the screen shot picture. The landscape is an "AnimatedMesh" even though it's not animated. I modleded it elsewhere. I am running a triangle selector for collision detection and gravity on the node in question (the tank). Any ideas on how to do this?
Thanks in advance!
Rotate node reletive to landscape
Maybe I should re-phrase this?
Okay, Maybe I should re-phrase this.
The tank won't drive up the hill because the angle is too steep. If the tank is rotated so that the front end is up in the air, it will drive up the hill. How do I make the tank always rotate itself so that it is driving parallel with the ground. Always.
Any ideas?
Thanks,
mtbal
The tank won't drive up the hill because the angle is too steep. If the tank is rotated so that the front end is up in the air, it will drive up the hill. How do I make the tank always rotate itself so that it is driving parallel with the ground. Always.
Any ideas?
Thanks,
mtbal
*best* way is a physics way - have 4 (3 would do) points which represent the corners of the tank, each one responding to gravity and checking for collisions with the terrain, then use some simple math to calculate the angle they're making with each other and set the tank to match. Of course, you would need some kind of restraint to keep those points at the corners.
This has the advantage of allowing the tank to jump over mounds slightly, for example.
simplest method, find the terrain height at the middle of the tank, middle + (0,10,0), middle + (10,0,0) and use trig to find the angle they're making. This will be less reliable and won't allow jumping, etc. but is much easier.
This has the advantage of allowing the tank to jump over mounds slightly, for example.
simplest method, find the terrain height at the middle of the tank, middle + (0,10,0), middle + (10,0,0) and use trig to find the angle they're making. This will be less reliable and won't allow jumping, etc. but is much easier.
I had kinda figured out that I'd have to do the latter. (This is a really small , and I'd like to avoid physics if I can.) But how do I find the angle of the face under the tank?DavidJE13 wrote:*best* way is a physics way - have 4 (3 would do) points which represent the corners of the tank, each one responding to gravity and checking for collisions with the terrain, then use some simple math to calculate the angle they're making with each other and set the tank to match. Of course, you would need some kind of restraint to keep those points at the corners.
This has the advantage of allowing the tank to jump over mounds slightly, for example.
simplest method, find the terrain height at the middle of the tank, middle + (0,10,0), middle + (10,0,0) and use trig to find the angle they're making. This will be less reliable and won't allow jumping, etc. but is much easier.
Thanks
well you say you're already using a triangle selector to find out the height under the tank. You can use the same method to find the height at 2 other points;
l = length of tank / 2
w = width of tank / 2
y1 = height at (tank.x, tank.z)
y2 = height at (tank.x + cos( yaw ) * l, tank.z + sin( yaw ) * l)
y3 = height at (tank.x - sin( yaw ) * w, tank.z + cos( yaw ) * w)
pitch = atan( (y2 - y1) / l )
roll = atan( (y3 - y1) / w )
setRotation( roll, pitch, yaw )
(yaw is the player-controlled rotation of the tank, pitch and roll may need to go the other way around. Also this all assumes that the terrain is aligned on xz. If it's on xy you'll need to do more complicated math.)
Obviously you'll need to play around a bit, and this isn't perfect math, but as long as the terrain is mostly flat, it'll be ok.
Finding the angle of the triangle beneath the tank might be possible (I don't know how to do that if it is) although I wouldn't recommend that even if it's far easier than this method - the tank's angle would be really jerky as it moved
l = length of tank / 2
w = width of tank / 2
y1 = height at (tank.x, tank.z)
y2 = height at (tank.x + cos( yaw ) * l, tank.z + sin( yaw ) * l)
y3 = height at (tank.x - sin( yaw ) * w, tank.z + cos( yaw ) * w)
pitch = atan( (y2 - y1) / l )
roll = atan( (y3 - y1) / w )
setRotation( roll, pitch, yaw )
(yaw is the player-controlled rotation of the tank, pitch and roll may need to go the other way around. Also this all assumes that the terrain is aligned on xz. If it's on xy you'll need to do more complicated math.)
Obviously you'll need to play around a bit, and this isn't perfect math, but as long as the terrain is mostly flat, it'll be ok.
Finding the angle of the triangle beneath the tank might be possible (I don't know how to do that if it is) although I wouldn't recommend that even if it's far easier than this method - the tank's angle would be really jerky as it moved