Hello, I have a tank that is a parent game object (a container basically, I just have a transform and some attached scripts on it) with the individual parts as child objects (main body, 4 treads, turret, etc.).
I have the controls set up with forward and reverse along z, and rotation along y axis for main body control, a turret that rotates along y axis and cannon that rotates along x axis. Because of the need to not go through other game objects and the desire for the quad treads to pivot to an extent with terrain movement I have set up rigid bodies and joints connecting the multiple rigid bodies (main body, turret, and treads all have rigid bodies).
I know to use quaternions for rotation, to move the game objects via rigid body, and to have the movement script in fixedupdate however I am having a problem with getting the turret to maintain its x and z rotation coordinates while rotating on y and to have the tank itself move forward, backward, and rotate altogether, it just jitters slightly in the direction of the control input when I attempt to do so, so I know the control inputs work it’s just not wanting to move. I’ve tried controlling both the parent game object (I assigned a rigid body to it to test it out) and the child game object that is the main body which the other game objects with joints are connected to, but the results are the same. Also, the turret stutters when I rotate it, something I suspect is because of the fixedupdate as I didn’t have this issue with lateupdate prior to going to rigid bodies.
I don’t have code attached because it’s a mess as I am currently trying multiple solutions to make it work and have gotten somewhat confused and lost as to how to go about this properly after trying multiple solutions that I had to figure out from other situations that I read about that were not quite like mine. So, I am sort of starting over so I can get my head on straight about this. I have gotten movement with controls to work previously with transform changes when I was trying to do something more basic, but in the process learned that I needed rigid bodies so I added them and slowly went from there to the point where I am at with multiple rigid bodies and joints, something I am not entirely sure about if I actually need, is such a setup even needed or am I going about this all wrong?
Thank you for any attempts at solving my problem.
This guy makes a cool “Kawaii Tanks” asset… it has a freakin’ crazy controller in it, with all kinds of suspension elements and drive wheels and turrets.
Check the “FREE” one because last time I looked it has the full controller in it.
Disclaimer: I haven’t actually used it “for reals” in a game, but I have played around with it a bit and I’m impressed.
Alright thank you I will give it a try.
I have most of it working at this point, but a weird issue is happening where the tank treads are partially sinking into the terrain.
I have 8 empty objects with sphere colliders and hinge joints that propel the tank via torque, 2 attached to each tread, when I apply enough force downwards or mass to the treads themselves it sinks into the terrain beyond these sphere colliders up to the tank body collider.
The treads themselves do not have any colliders at this point so as not to interfere with the sphere colliders since they belong to different objects (I read this can cause an issue).
If I apply mass to the tank body itself the problem occurs but only goes so deep, even with continued increase to the mass the sphere colliders only go about halfway into the terrain. Also, if I apply downward force to the spheres themselves it only goes about halfway as well, it just seems to be when applied directly to the treads. Also, the Sphere colliders seem to remain above the terrain and only the treads themselves sink, but I do not have any spring or distance travel for the spheres, as mentioned they are directly attached to the treads via a hinge join in the x axis for rotation (already checked to see if they are all set correctly all set correctly).
the treads and empty objects all have rigid bodies set to discrete collision detection, no freeze positions or rotations, and is kinematic not checked.