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.
Still have not figured it out yet, itâs almost as if the sphere colliders that are acting as wheels for the tank are snapping from the joints, but are still connected, as they function fine when force is applied and the break force and break torque for the hinge joints are set to infinity. with testing of changing mass to the tank body in play mode the sinking starts just past 100 and continues gradually until the collider for the tank body meets the ground, and as mass is reduced it gradually moves back above ground, with it appearing as if the joints have freedom of movement on the z axis, but actually donât since they are hinge joints on the x axis, very unusual to me. This post is somewhat of a reiteration from the last post I made but wanted to clarify that it seems to be related to the joint connection between the âwheelsâ and track segments. I am stumped currently and will be moving on to other tasks in my project for the moment but will still be checking this thread for any replies that are given.
Still have not figured it out, I have decided to switch to wheel colliders, seems to being going well enough. Thank you to Kurt for the Chobi asset reference, it definitely helped with my problem apart from the sphere collider issue.