I am messing around with chaos vehicles and I got it right for the car to drift with just tweaking the Vehicle Movement Component but I would like to implement a steering assist into the vehicle I am using. Basically I want the wheels to point forward when the car is sliding. A similar effect can be seen in games like Assoluto and CarX drift racing.
Is this entirely a visual thing, or is this an actual control thing?
If it’s visual, you’ll need to insert yourself between the computed/simulated state, and the rendered state, to render a different mesh than what’s used for computation. Make sure the render mesh is rendering but not colliding, and the computed mesh is colliding but not rendering.
If it’s actual control, then perhaps the best way to do this is to wire this up where the player control is read in the controller.
In the “input axis steer right” event, you could check whether you’re drifting (or, perhaps, even calculate “how much” assist is needed,) and then calculate what you “want” the steering to be, and then calculate some blend of the user input and the desired input, and forward that to the physics component. This would also let you implement a setting in the UI for how much steering assist the player wants; you’d simply use this setting as an input to the function for how much assist to apply in the blend function.
Thanks for the response bud. This is entirely for control, it’s kind of a necessity as the car spins out because I can not react quick enough. Forgive me I am very new to Unreal Engine, have only been using it for a few months. Is it possible to show what you explained in Blueprint form? So that I and anyone else who has this idea can use it in our own projects?
You would need to adjust the direction of the steering programmatically with trigonometry.
From the car forward vector, look at location with B being a point on the spline you are supposed to follow.
Well, ok. Since you are new to it maybe a bit more info is needed.
Cars travel on roads. Roads are made with splines.
Fetching a point on the spline close to the car (or character) is fairly standard.
In this case, I would do it with a cone sweep though.
Because if the player turns opposite it will eventually disable the correction.
So, a cone sweep detects the spline, and calculates the point on the spline at the edge of the cone.
With that point, and actor forward vector, you solve the angle at wich the steering needs to be adjusted.
Then you slowly correct the angle the player is inputting by adding in a fraction of the angle you need and updating the needed angle.
The result should be similar to fake steering where you don’t have to do anything for the car to follow a path, but you can still have some control to alter the path / micro correct.
A cone being tighter at the start than further out, could possibly mean that some drifts will put you in a spot that auto steering cannot work.
You have to try it out and see where collisions happen…
This method seems very limited. I want this to work everywhere, even off road where you drive on a landscape
If the user is driving on an arbitrary landscape, how do you know where they want to go?
And if you don’t know where the user wants to go, how can you “assist” them going anywhere?
Basically I want the car to turn the wheels to correct a slide. Below is a video that shows what I mean. Watch from 3:11 to 6:12
I pledged on his patreon and downloaded the component but the vehicles are physics constraint vehicles and I am using Chaos Vehicles. Also his component is written in C++, something I know nothing about. I want his steering correction feature (or something similar) in blueprint form that works for Chaos vehicles.
Sorry if I did not explain well enough what I meant. If more example footage is needed, let me know.
If you can alter the steering input for the player, then that’s pretty simple.
- Get the “right vector” of the car chassis (in world space)
- Get the chassis world velocity vector
- If the velocity length is smaller than some number, don’t correct anything and stop here
- Normalize and dot product the chassis-velocity vector with the chassis-right vector
- Multiply the value you get out with some scaling factor (start with 1.0 and tune up/down from there)
- Add the result of this multiplication to your steering input axis signal, and clamp the result to the [-1 … 1] range
- Use this result as the actual input for “steering” in the car controller / physics
The math result of this is that “the larger the part of the cars velocity is to the side, the more steering correction is applied,” which works great for correcting drifting (four-wheel skidding.)
If you also want to correct two-wheel skidding (fishtailing) then you’ll want to also get the cars rotate velocity around the up axis, multiply by some factor (may be negative, depending on how rotation is measured) and add that, too. This will correct more the faster the car is turning. BUT this will also make the car have more understeer, because the car rotates when just turning, too – just not as much.
@jwatte You sir are a genius. Thank you so very much. This has been bugging me for months. Here it is in blueprint form.
I wouldn’t call this a “steering assist”.
Maybe that’s why you couldn’t find a satisfactory solution up to now…
This is more of a traction control solution - you are literally compensating for the engine simulation by increasing the steering power.
The “correct” solution would be to alter the actual physics that are calculating the slide in the first place.
Not sure how far the engine has gotten with implementing chaos vehicles - will check on it in the coming week actually.
The point being, it should be possible to alter the values to achieve a controlled traction (more grip) similar to what you are doing by adding into the steering…