Hi All,
I’m in the process of making a 3 lane racer game and have come to the point where I really need to decide whether to use rigidbody physics, custom physics, or a mixture of the two. This game uses bezier curves as the foundation of the movement, so the traversal of space is separated from rigidbody physics at the most basic layer. Below is an example of the movement I currently have:
The pill object is a child of an empty game object, where the parent object is always on the bezier path and by default at the base of the pill object. The jumping as of now is also separate from unity physics.
private void Jump()
{
transform.localPosition += Vector3.up * jumpRate * Time.deltaTime;
jumpRate -= gravity;
if (transform.localPosition.y < racerMidPoint.y)
{
isInAir = false;
jumpRate = jump;
if (transform.localPosition.y != racerMidPoint.y) {
transform.localPosition = new Vector3(0, racerMidPoint.y, 0);
}
}
}
I want to add in rams and other obstacles to the paths, like so:
I want the pill to traverse this path upwards, increasing its y local position in the at the same gradient as the object it is travelling over. This object may not be an object as simply as a ramp, it may be like a bump in the road. This is presenting me with an issue. Since these objects are not part of the curve the pill will automatically ignore these ramps if a rigid body is not place in it. My ideal behaviour would be the pill would automatically traverse the topography of any object placed on the road, with the local y position, and therefore the ‘down’ direction of the road, being direction of gravity.
What I almost looks like this:
I have tried adding a mesh collider and rigidbody to the ramp, setting it to convex to the ramp, and adding a collider and rigidbody to the pill but the results aren’t quite what I would like. I thought locking the x and z coordinates on the pill rigidbody would help me here, though it doesnt quite work. Enabling gravity on the rigidbody also creates undesirable situations when the road turns upside down. Rigidbodies in general also seem intend on moving slightly around even when I try and lock them down, making them a pain to work with in this situations. Ideally the rigidbody would only ever modify the local y position when in contact with a ramp or other obstacle, and NEVER anything else. This would be my ideal scenario.
Essentially I want to be able to keep this system as simple as possible whilst fulfilling my requirements. What kind of approach seems like it would be the best for these requirements: using rigibodies, ignoring rigidbodies and crafting my own system, or a mixture of both?
If I’ve made anything unclear please say and I will attempt to clarify!
Thanks in advance