The problem in unity was that no matter what… there was always a very small amount of rotation left on the main rigid body… no matter if you came to a complete stop yes or no.
So this resulted in the tank slowly rotating when you where standing still.
From what I understood This_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation is actually not a constraint actor but a rigidbody constraint. Something that is used if you are making a sideview game for example, where you would lock all of your actors to a XZ plane. This didn’t worked for some reason, most likely because you are not suppose to switch it on in realtime.
The next thing I’ve tried is to put body to sleep and this worked really well. Logic is simple, if there is no input from player and both linear and angular velocity are lower than some N value then body is placed into sleep and all chain of functions to update animation, suspension and etc. is switched off. Later it wakes up automatically as soon as user provides input. Physics bodies wake-up on collision as well, unfortunately suspension doesn’t wake-up in such scenario. There is no function in blueprints to check if rigid body is sleeping, so I would need to check velocity again and enable main execution graph for suspension and animation to start working again.
Sleep implementation allows to avoid some small sliding on sloped surfaces, but it’s main purpose is to disable unnecessary computations for performance reasons. The downside of such implementation is that if turret is a physical object with mass connected to main body of the tank, it will keep it awake and tank will keep drifting. I need to improve friction calculation to avoid this.
Still need to test option with adding and removing constraint actor or using constraint of ridigbody. I need to check if it works by adding and removing constraint on the same frame, or removing it at next frame. In any case it needs to be automatically removed otherwise the vehicle will stick to the ground and it will look very weird if you collide with it.
New update is out on GitHub.
Added automatic sleep mod:
The idea is to put vehicle’s rigid bodies to sleep if it’s not doing anything. PhysX will do that for you automatically and wake-it-up as soon as some force is applied, like collision. Unfortunately that doesn’t work in our case because suspension keeps pushing main body on every tick. I’ve added a small routine where current velocity of the vehicle is compared to some minimal allowed velocity. If current velocity is lower than body goes into sleep and the whole vehicle update graph is ignored. It will wake-up if something collides with it or when player tries to steer vehicle or accelerate/bake.
vehicles inherited from ATracked_Vehicle got a new variables SleepVelocity and SleepTimerSeconds
SleepVelocity is a minimal velocity under which vehicle will go to sleep. Value of 10 is enough for M113 to not slide sideways on 5 degree sloped surface
SleepTimerSeconds is amount of seconds between sleep check. It’s necessary for it to be at least more than 1 second otherwise vehicle can perpetually hang in air or not wakeup when you try to steer it.
to see if vehicle is sleeping, posses it and enable debug mode [shift+alt+d] it will wakeup because of this, but later will go into sleep
This doesn’t solve the problem of friction either being not enough or not being simulate properly, so while on 5 degree slope M113 will fall asleep it won’t fall asleep on 10 degree slope as there is not enough friction force applied. One could go with higher than 10 values of SleepVelocity, but at about 50 Ripsaw can just stuck in the air while swinging on it’s bouncy suspension. So be aware of this, I don’t know if 10 units is good (10cm/s?) it seams to work well enough. Let me know if I need to make it smaller by default.
Nice, now I can check if I’ve setup my Git repository right
I should be able to update now.
I also moved the cv into the new code.
The rotate 180 in the wheelanimation function works.
And did the new wheel aniamation setup, which indeed is easier then the first method.
As a driver it’s fine the way it is… If you have a tank with manual gear you have to shift gears, and as soon as it’s done the automatic transmission for modern vehicles.
You have the throttle the way it is now making it an immersive experience.
I would also love to see a driving mode when you are controlling the vehicle as the Vehicle Commander.
I don’t know if you ever played Steel Beasts, and ArmA also has somewhat the same system.
Basicly you split the movement of the tank into 3 forward versions (Foreward slow, Normal Speed, and Fast) and a reverse speed (Maybe even two, Reverse slow and a fast reverse when under attack).
All you do is press forward once and it continues to move forward slow speed, press again and you go normal speed etc. Press S is stop and in steel beasts x is reverse.
This way you can concentrate on scanning the environment as a TC and not worry about driving.
That would be awesome! Are you really happy with how it’s done in Arma? To be fair I didn’t used tanks that much in singleplayer since Arma 2 and not sure if command control was improved. I have over a thousand hours in it, but mostly from multiplayer.
For commander control I should add automatic transmission + automatic reverse first(if you press back key when standing still).
Then it can be made as a simple switch, where you can switch between manual control and command controls. Later you could use the same mechanics to board tank at different spots [driver, gunner, commander and etc.], gaining different controls.
Keeping specific cruise speed should be easy. For turns, instead of how arma does it, you could select a “sharpness” of the turn just by holding turn button longer. How is it done in SteelBeasts?
No, ArmA tanks did not really change since version 2 and still suck big time if you ask me.
I’ve recorded a quick video of the basic movement controls in Steel Beasts for you (also because I had to test my recording software anyway to start recording a few introduction videos to your blueprint )
In SB you just use wasd and x.
The difference is that when you are the driver you have sort of an incremental throttle. hold the w key and it will go foereward faster… release it and it will continue to cruise at that speed.
Steering is with a and d. Reverse is the same as w but you use x and is also incremental.
When you are the commander or observer you just give the driver the order to go foreward and it will start at slow speed. Hit w again and it will go faster.
You can steer yourself by using a and d but you can also order the driver to steer to the left or right with increments of 22.5 degrees bij using shift + a or d
Thank you! This is pretty clear now. It’s nice that they allow both smooth and discrete steering from the seat of commander. I need to look into one more fix for suspension and then will add automatic transmission.
I have recorded the first part of a small Tutorial on how to setup your Blueprint.
Having a bit of trouble with my mic.
Let me know what you think and if I’m saying something stupid
The first part is The replacing of the assets inside a copy of the M113 blueprint.
The next video will be about connecting them in the functions
and the final one will be about the tracks.
I referenced to this thread in the video description so people can find it.
If it’s good enough you can put it also in the start post.
I’ve hidden majority of Internal variables, just few will still be visible in child blueprints, so the list on the left side will be much smaller.
Almost done with the automatic gear box. It kind of works but code is a mess and it skips first reverse gear. Will upload fresh version when it’s done.
AutoGearBox - is if you want to have it enabled/disabled by default
GearUpShiftPrc - is a percentage of maximum engine RPM at which automatic up-shift will be done
GearDownShiftPrc - is a percentage of minimum engine RPM at which automatic down-shift will be done
Important detail in this update is that you need to setup your neutral gear as 0.0 coefficient between reverse and forward gears [it was like that before, but it’s important to be consistent for automatic gear box]:
Starting from 0 you list reverse gears, then neutral as 0.0 and then forward. For this specific screenshot order is following: R3-R2-R1-N-F1-F2-F3
Algorithm will look for neutral gear in constructor, so you don’t need to bother of setting it up.
Default gear box now have 3 reverse and 3 forward gears. M113 have proper gear box with 1 reverse and 3 forward and Ripsaw is using default set.
Known issue: in the last forward or reverse gear you still can reach “red zone” of the vehicle, where engine doesn’t provide power anymore, without power you can’t steer it. I need to look how it can be fixed gracefully as “red zone” is important part of mechanics.
Hidden internal variables which you are not suppose to tweak, list of tweak-able parameters should be easier to read now. Ideally [performance] should be split into multiple categories “engine”, “suspension”, “gear box” and etc.
EDIT:
I’ve removed a first keyframe from engine curve. First keyframe was previously set to zero and is not necessary anymore. The last keyframe is still necessary as it’s drop to 0 imitates “red zone” of the engine.
There’s currently something fishy with the Automatic gearbox.
When you put the gearbox to manual, the S key is the brake… all fine here.
Now when I switch to automatic there is no brake and S is reverse only.
When in automatic mode I think I would prefer the Steel Beasts solution where S is the Brake Like in Manual mode And X is reverse throttle (or backward for that matter)
It should brake when you have some speed forward or backward. If speed is lower than some value (10cm/s I think) then it will start moving in direction of button press, otherwise it will brake. Or you mean something else?
EDIT: To be more clear. If tank is moving forward than back key is brake. If it’s moving backwards than forward key is brake. This is suppose to be more “typical” game controls.
I can make a separate binding for Steel Beasts version of controls. Which is much easier to implement as I don’t need to bother with measuring speed and deciding which way it’s moving and which button should brake it.
Wait never mind, I had part of an old blueprint running so had no automatic brake somehow?
The current for auto transmission is great as it is… no need for a brake key.
The only thing that could be annoying somehow Is that when you hit the brake by hitting reverse to stop it goes into a reverse gear. So when you stop this way and want to turn you turn in the opposite direction because it is in a reverse gear.
But as soon as you know this you hit foreward once before turn to make it go into foreward gear… so I don’t think this is a big deal.
You only need to use S as the brake and X as reverse when you implement a movement mode like we talked about when you operate a tank as the TC or from an outside view and don’t want to bother about driving.
(The Steel Beasts type of control where it will just go)