Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Randomation Vehicle Physics 2.0 - Now open source on GitHub!

Discussion in 'Assets and Asset Store' started by JustInvoke, Mar 14, 2015.

  1. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    For dynamically changing the numbers around the pointer on the meter, you would have to write some code to automatically generate more UI objects with incrementing numbers in them. They would have to be uniformly distributed around the pointer with increments measured by (2*pi)/(quantity of numbers). 2*pi would be a full circle of numbers, so you would have to decrease this to represent the portion of a circle occupied by the numbers (notice how the bottom of the meter pictured is cut out like a pizza). You could use the Mathf.Sin and Mathf.Cos functions with the increasing angle measured in radians. For dynamically creating more UI number objects, you could create a basic single-number object as a reference, then duplicate that at runtime and set each duplicate's UI text to match the current number increment. You would also have to scale the rotation of the pointer to match the range of RPMs represented by the meter.

    Does that answer your question?
     
  2. SomerenV

    SomerenV

    Joined:
    Dec 20, 2011
    Posts:
    68
    I'm not sure anyone is still checking this topic but I've got a problem. I've taken the F1 car as the starting point, swapping out the meshes. Problem however is the following: the F1 car handles really nice but my car doesn't. As soon as you take a sharp corner the car spins around. Same goes for drifting. The F1 cars has a nice controllable drift whereas my car doesn't. Tapping the brakes or e-brakes at speed makes the car spin around instantly. Here's how both cars compare.



    I'm pretty sure it has something to do with either the wheels being further out from the car, or the size of the wheels. I've tried a lot of setting but nothing seems to do the job. So how do I get the handling from the F1 car transferred to my buggy?
     
  3. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    The position of the wheels is probably what is causing the issue. A couple ways to try and reduce spinning out is to increase the sideways friction of the rear wheels, or increase the height of the peak of the sideways friction curve (or move it to the left a bit). You also might want to look at the VehicleAssist script on the root transform, where the drift assist properties could be leading the car to steer into drifting more readily when skidding just slightly.

    Alternatively, you could try reducing the sideways friction of the front wheels slightly, but this will probably lessen how sharp you can turn.
     
  4. zmaxer

    zmaxer

    Joined:
    Jul 22, 2015
    Posts:
    4
    Thank you very much!
     
  5. MS24

    MS24

    Joined:
    Mar 1, 2016
    Posts:
    5
    Hi everyone!
    First of all, I am not a driver and not much of an expert in the laws of physics. I have a question regarding a strange behavior of the RVP vehicles that occurs when we accelerate while turning the wheels.

    To put it simply - in a situation when the car runs at high speed, I would imagine it would start losing the velocity (or at least maybe maintain it) when we take a sharp turn while still accelerating. However, while testing some cars from the RVP pack I have noticed a contrary behavior to occur. When I turn the wheels while still accelerating, the car actually seems to be gaining speed way faster than when going straight. In fact it looks like the car gets a power boost when we do this. I think I might've already solved this issue somewhere in the past, but after a while unfortunately I totally forgot what it was about.

    I would be very grateful if anyone would be able to clearly answer what might be the reason behind this behavior, and what setting/settings actually have the impact on this part of the physics.

    Thank you and have a great time!
     
  6. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    The first thing that comes to mind is the drift push property on the Vehicle Assist script attached to the root transform. This is used to help the vehicle accelerate while drifting, but sometimes a little bit of sideways velocity can trigger it even when not drifting. You could try setting it to zero or disabling the script entirely in case another property is causing the problem.
     
  7. MS24

    MS24

    Joined:
    Mar 1, 2016
    Posts:
    5
    Hi, thank you for your answer. I know this is an already closed project for you, so I truly appreciate you giving away any support on it. Unfortunately disabling vehicle assists didn't solve this issue. I was experimenting with lowering rear tires friction value and adding some angular drag which partially "did something", however the end result wasn't really the one expected. This made the car accelerate little slower with wheels turned and had a negative effect on traction, but I wasn't able to reach the point where the car would drop on speed.
     
  8. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    It could be a side effect of the front wheels' sideways friction. The friction force applied to prevent the wheels from slipping while turning might somehow be assisting the acceleration of the car while turning. Like the friction force is pushing the car into the turn on top of the actual drive force from the driven wheels.

    I just opened the project and noticed that the monster truck has the same problem, so maybe it's a subtle effect caused by the suspension forces when the body of the car rolls, or maybe it has something to do with all of the wheels being driven.

    It could also have to do with the slip dependence property on the wheels, where the tiny amount of slipping occurring during turns is triggering the forward friction curve of the wheel to be evaluated at the peak, increasing the forward friction through which the driving force is applied.

    This is all I can think of and about as deep as I'm willing to go on this issue, I hope it gives some insight into a potential fix.
     
  9. MS24

    MS24

    Joined:
    Mar 1, 2016
    Posts:
    5
    Thank you for your input on this matter. I will be performing some tests today and when I get to the bottom of this, I will post an answer here with the definite solution.
     
  10. MS24

    MS24

    Joined:
    Mar 1, 2016
    Posts:
    5
    I think I have went through all possible settings and none of them let me achieve the desirable outcome. Unless a combination of a couple different settings would be the answer, I'm afraid not much can be done.

    However I have made an observation, concerning the behavior of Hover Car. I wanted to find out what causes it to slow down during turns. It is the "Side Friction" setting on the HoverWheel script attached to its wheels. I do understand that this has almost nothing to do with how the regular RVP cars work, but I feel that this might be a good starting point for the further investigation. Perhaps it would be even possible to somehow "inject" the Side Friction value into the regular car Wheel script.
     
  11. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    The side friction variable on the HoverWheel script is just a float number, not a curve. The script uses this to linearly apply friction force based on the local sideways velocity of the wheel along with how close it is to the ground. You can try copying and pasting the line involved with sideways friction to the Wheel script, but it probably won't give good results. The friction calculations are in the ApplyFloatDrive() and ApplyFriction() functions of each script respectively.
     
  12. MS24

    MS24

    Joined:
    Mar 1, 2016
    Posts:
    5
    Thanks for the tip. I noticed that Side Friction in Hover Car works pretty much as a sort of a side break which is applied when the car passes its "air traction" ability limit. Plus it has to be noticed that the HoverWheel script is in fact a combination of both "wheel" and "suspension" scripts, if we are to compare it to the regular RVP cars, so it might be a bit tricky to try and merge the calculations of some of these settings. I'll try to come up with something that would do the trick. I found out that the only similar thing in regular cars, that applies breaking power without us manually using the break is the Axle Friction, however this one pretty much acts like a regular drag force.
     
  13. zelderus

    zelderus

    Joined:
    May 20, 2016
    Posts:
    4
    In Unity profiler I saw some memory leaks - meshes count increase forever. It's a tire marks dont destroy generated meshes. In 'TireMark' class (in TireMarkCreate.cs file) add this for fix:

    Code (CSharp):
    1. void OnDestroy()
    2. {
    3.     var mf = this.gameObject.GetComponent<MeshFilter>();
    4.     if (mf)
    5.     {
    6.         Destroy(mf.mesh);
    7.         Destroy(mf);
    8.     }
    9.     mesh = null;
    10. }
     
    Last edited: Aug 29, 2018
  14. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    Ok I will take look at this at some point. I assumed the garbage collector took care of those.
     
  15. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    I know this asset is not more getting supported but i still want to ask if someone could make a tutorial how to setup the damage system for a car.

    I am having a problem with getting detatchable parts working. They just don't break or fall off.

    I am using the muscle car prefab, disabled the chassis put all the drivetrain stuff in my model and than copy pasted the detatchable part script on my bumper part, and configured the anchors. however. did i forgot something?
     
  16. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    Did you add the detachable part to the list of displace parts on the main damage script? The vehicle damage script is what evaluates the collision and calls the detachment method. Displace parts is the list of objects that are offset in local space upon collision and within this process they are evaluated for detachment if they have the detachable part script attached.
     
  17. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Yes, I have already done that. I also did the same hierarchy setup and selectet the right layers for the gameobjects. The manual is also not very detailed at that point. Is there a chance that you could make a quick setup video for the damage system with some explanations what to look for? :)

    Edit:
    Is the breaking of the detachable part somehow bound to the damage or strength factor from the damage script or the scale of the car?
     
    Last edited: Apr 27, 2019
  18. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Ok, I found the problem. I had set the Max Collision Magnitude from 100 down to 0.9. Now the bumper breaks again but the car deformation is ... wierd... just a little hit blows my model up like a balloon. And if I turn the damage factor down it´s not breaking again. any idea ?? :)
     
  19. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    What is the range of the damage factor you are trying? Is there a massive difference in deformation with very small adjustments to the variable? It's been a long time since I worked with the code so I would have to dig into it to figure out what the problem could be.
     
  20. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Fixed it, yes little changes in values did a big impact on deformation. I added now a new int which multiplys with the max magnitude value but only in the detachable part in the script. the rest of the script does not use the multiplyed value. So yeah it's working well ;) Thanks for this awesome asset!
     
    JustInvoke likes this.
  21. BoneyPile

    BoneyPile

    Joined:
    Apr 20, 2014
    Posts:
    12
    I know this isn't really supported anymore, but is there a way to get the camera to follow the cars rigidbody momentum direction like in rvp1?
    For instance, if you hit a big/steep jump in rvp2, the camera points toward the sky. however when coming back down, its still pointing to the sky. it stays aiming at the sky until you land. it should angle down and follow the rigidbodies velocity direction that way you can see when you are going to land. Not necessarily which way the car is pointing, but which way its momentum is going.
    I see how forwardDir works. and it seems like should happen automatically. I know its going to be something simple I need to change.
    I was just going to implement the rvp1 camera, but this new controller is so much more condensed and precise. So I would hate to switch controllers.
    Any advice?
     
  22. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    At the start of the FixedUpdate method in the CameraControl script you should see the following if statement. Try adding the following else block after it. The camera movement is a little odd when the car is falling straight down but it generally works.
    Code (CSharp):
    1. if (vp.groundedWheels > 0) //Original block
    2. {
    3.     targetForward = stayFlat ? new Vector3(vp.norm.up.x, 0, vp.norm.up.z) : vp.norm.up;
    4. }
    5. else //Add this block
    6. {
    7.     targetForward = targetBody.velocity.normalized;
    8. }
    I chose to adjust targetForward instead because there are a series of calculations starting with this variable that ultimately end up setting the forwardDir variable. This way the camera controls will still work properly.
     
  23. BoneyPile

    BoneyPile

    Joined:
    Apr 20, 2014
    Posts:
    12
    That is perfect! Thank you. I was definitely going about it wrong. I was normalizing the velocity, but in the wrong places. Works exactly like I needed.
     
    JustInvoke likes this.
  24. Chimaera987

    Chimaera987

    Joined:
    Feb 28, 2017
    Posts:
    35
    Hi! First of all, great asset, but I can't seem to figure out how to load cars between scenes. DontDestroyOnLoad doesn't work. It gives me an error that the transform is destroyed and I'm still trying to access it. The car is carried over to the other scene, but it's not driveable. Any help would be greatly appreciated.
     
  25. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    I don't remember exactly how the dependencies are set up, but it could also have something to do with the manager objects in the scene if those aren't being carried over. What is the transform variable name or what line is the error coming from?
     
  26. Chimaera987

    Chimaera987

    Joined:
    Feb 28, 2017
    Posts:
    35
    I tried putting GlobalControl and TimeMaster too in an empty and carry that over but it still does nothing. I tried using the original project too. It's not a problem in the script I wrote, since the car with the wheelcolliders works just fine.

    The problem is on the VehicleParent script on line 231. It says: "MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. RVP.VehicleParent.FixedUpdate () (at Assets/RVP/Assets/Scripts/Vehicle Control/VehicleParent.cs:231)"

    There are other scripts that say something like this, but they are all dependent on that vp.norm in the VehicleParent script from what I saw.

    That line can be traced back to this:
    //Create normal orientation object
    GameObject normTemp = new GameObject(tr.name + "'s Normal Orientation");
    norm = normTemp.transform;

    So, any ideas? I'll send you the files if you want. I saw that you can save things as prefabs then load them into another scene, but that seems excessive, when this could work with one small line of actual executable code.
     
  27. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    What if you tried calling DontDestroyOnLoad on the norm object? This temporary object is used for assisting with orienting the vehicle relative to the ground normal and there are a fair amount of dependencies around it.
     
  28. Chimaera987

    Chimaera987

    Joined:
    Feb 28, 2017
    Posts:
    35
    Yeah, I actually done this not so long ago and came to tell you that it's "fixed". I just started to learn code, and I didn't really understand what that does or what it is needed for, so I thought, why not ask you about it. Anyway, thank you.

    If anyone has this problem just add DontDestroyOnLoad(norm) after those lines.
     
    JustInvoke likes this.
  29. ajith_sreenivasan

    ajith_sreenivasan

    Joined:
    Aug 29, 2018
    Posts:
    6
    I'm having trouble in setting up own vehicle :(
     
  30. Chimaera987

    Chimaera987

    Joined:
    Feb 28, 2017
    Posts:
    35
    What I do is that I drag a car body prefab in the hierarchy, drag in an car prefab that suits the characteristics of my car, drag the car body in the said prefab, delete the body, delete the colliders(since I already have them in my car body), move the suspension and done. As for performance I just type in the real values and increase the forward tire friction until I get the desired 0-100 time. It's not really realistic, but this asset is not made for a racing sim.
     
    ajith_sreenivasan likes this.
  31. ajith_sreenivasan

    ajith_sreenivasan

    Joined:
    Aug 29, 2018
    Posts:
    6
    How do you change the wheels?? coz when I try to do the wheels are always rotated on wrong axis
     
  32. Chimaera987

    Chimaera987

    Joined:
    Feb 28, 2017
    Posts:
    35
    I keep the hierarchy as is, remove all the visual wheel stuff, so there's only the transform, drag my wheel object into rim or tire. Since I currently use forza models for testing i have all of the wheel meshes in an empty, I rotate -90 or 90 the meshes inside it, NOT the parent that it's in. That should do it. Sadly, however much I like this asset I have to abandon it. It's way too unrealistic for my needs, so if you make something remotely realistic car spec wise, I'd start looking somewhere else.
     
  33. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    That is one of the main problems with the way I originally designed the asset. If I ever make another physics package, I will make sure that there is a clear process for creating things from scratch rather than modifying template objects.
     
  34. BoneyPile

    BoneyPile

    Joined:
    Apr 20, 2014
    Posts:
    12
    I have a sound for a blow off valve.
    I want it to play whenever you release the throttle. Since throttle is an axis and not a simple as a getkeyup, I'm having trouble on how to fire the sound and where the best place would be.
    So, How can I tell when the player releases the throttle axis? I guess you would have to check if accelInput goes from 1 to 0, then fire the sound. This would work fine using a keyboard. However, if someone was using a joystick, it would have to release to exactly 0 to fire the sound. Its almost like I should create some sort of accelInputReleased bool... I'm just trying to wrap my head around it. Was hoping you could help.
    also;
    Should I set it up under
    "Set engine sound properties" in motor.cs
    Or in vehicleparent.cs?
     
    Last edited: Nov 7, 2019
  35. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    You should probably add this feature in the motor script. I suggest adding a bool like you said plus a float tracking the accel input from the last frame for comparison. When the current accel input falls below your threshold and the previous accel input is above or equal to the threshold, play the sound (or set the released bool to true). You could add a public float to set the threshold in the inspector.

    Something like this might work:
    Code (CSharp):
    1. //Variables
    2. public float throttleSndThreshold = 0.1f;
    3. float accelInputPrev = 0.0f;
    4. bool accelReleased = false;
    5.  
    6. //Logic in Update()
    7. accelReleased = vp.accelInput < throttleSndThreshold
    8.      && accelPrev >= throttleSndThreshold;
    9.  
    10. if (accelReleased)
    11. {
    12.      PlaySnd(); //However you want to play the sound
    13. }
    14. accelPrev = vp.accelInput;
     
    BoneyPile likes this.
  36. BoneyPile

    BoneyPile

    Joined:
    Apr 20, 2014
    Posts:
    12
    That is great thank you!
     
  37. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    314
    Hi @JustInvoke
    Could you explain for me. How did you implement body roll physics ?
    Thank in advance !
     
  38. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    I assume you're specifically talking about rolling over a vehicle after it gets stuck upside down. There is a function in the VehicleAssist script called RollOver that basically checks above and to the sides of a vehicle with raycasts then applies torque on the vehicle to turn it over.
     
  39. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    314
    Hi,
    Thanks for your reply. I mean, vehicle body roll like below video:
     
  40. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    It's just a natural side effect of the suspension and the center of mass being above the ground. When a vehicle turns, the wheels are pulling it sideways which makes the vehicle want to tip over, but the suspension forces are pushing up to support it and counteracting the tipping. A vehicle with a high center of mass would roll all the way over sideways.
     
    CoderPro likes this.
  41. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Hi @JustInvoke
    I am trying to use the followAI. So far I have the chase ai prefab in my custom scene and the GlobalControl. I created some transforms with the vehicle waypoint script on it. The problem now is that when I start my scene, the chase ai starts to drive but doesn´t follow the waypoints. Did I missed a setting?

    thank´s ;)
     
  42. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    Have you set the next point variable on each waypoint to connect the waypoints? There should be magenta lines drawn between them if they are connected. I just tested it by dragging the chase car prefab into the demo scene and setting the target of the FollowAI script to one of the waypoints and it followed the path correctly. Does the chase car prefab work in the demo scene for you?
     
  43. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Yes it does work in the demo and i created a waypoint path and appyed a waypoint as follow object. Maybe I dont have the right layers setup?
     
  44. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    Does the AI just drive in a straight line, or is it driving in circles? Make sure the waypoints are close enough to the ground such that the yellow radius gizmo is clipping into the ground. If cars can't get inside the radius then they won't advance to the next point. Layers should not affect AI behavior other than the view block mask which defines what objects can block the view of the target waypoint. You could try setting the view block mask on the FollowAI script to ignore all layers/"nothing".
     
  45. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    67
    Hi and thank´s so far,
    Yepp the AI just starts driving in a straight line. The waypoints should be well positioned and the block mask is set to "nothing". Any other ideas?
     
  46. JustInvoke

    JustInvoke

    Joined:
    Jul 16, 2012
    Posts:
    340
    Unfortunately I don't have an answer for what could be causing it. I would have to take a look at the project directly if possible. You can send it to me at justin@justinvoke.com.
     
unityunity