![]() ![]() We’ll also untick Use Gravity, as we will be handling gravity ourselves. ![]() Lastly we give it a box collider to detect collisions with other scene objects and also to prevent the vehicle from falling through the terrain when the downward velocity is very high and we’ll put it on its own layer ( vehicle), so we can ignore it in the raycasts. These figures work quite well as they are, but you can achieve different handling effects by tweaking them also. We’ll also attach a rigidbody component, and for this example we’ll give it a mass of 70, drag 3 and angular drag 4. Notice that they are placed vertically above the centre of the vehicle, this is because of the way we simulate gravity in our code, as I’ll explain a bit further on. The red circles indicate where the hover points are positioned. This is a very basic example of how we would set up the vehicle game object with the hover points. However by increasing the hoverheight and hoverforce you can simulate a nice hover car type behaviour instead. The length of the ray we fire can be adjusted, and the longer it is the further the vehicle will float above the ground, we will be using a fairly short ray, because we want this to appear as if it is actually on the ground. So effectively the closer the vehicle gets to the ground the stronger it is pushed back away from it, and vice versa. We also adjust the strength of the upward force depending on the distance from the vehicle that the raycast detects the hit. The way we’ll achieve this is by firing a raycast down from each corner of the vehicle a certain distance ( hoverheight), and if it detects a hit, it adds an upward force. ![]() This is aimed at people with a reasonable knowledge of C# and Unity as I won’t be explaining in depth basic C# programming concepts or basic Unity concepts, unless it is appropriate to do so within the scope of the tutorial.Īs this is a tutorial on coding rather than building game objects in the editor, I’m not going to give step by step instructions on how to put together the car and terrain, instead I’ll just give a brief description of the important bits and how they relate to the code, and I’ll provide all assets in a download link at the end of the tutorial.įirst of all I should point out that the method we will be using isn’t a realistic physics simulation, instead it uses forces to ‘fake’ the physics, but the outcome is reasonable and gives a nice Mario Kart style feel to the vehicle handling. As with my previous tutorial, in an attempt to keep it as clear and concise as possible I will keep the game design quite simple, therefore this should be seen as a basis from which to build a game, rather than a tutorial for a complete and finished game. In this tutorial we will look at how to set up arcade style vehicle physics on a 3D model. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |