- Home /
Object colliding with collider junction instead of sliding over it
Hi!
I'm trying to make a train follow a rail, and I decided to do it with physics.
My train has each whell as a separate object, and each of these has a capsule collider in the side of the wheel to prevent it from derailing. On the top of that, I have a wheel collider on another object put on every wheel, to keep it on the top of the rails, as seen in the pictures below.
My rails on the other hand also have two colliders, one for every rail (on the same object).
To move the trail I made a really simple script, where I basically apply a specific torque to the wheel colliders.
private void FixedUpdate()
{
float torque = motorTorque * forwardInput;
foreach(WheelCollider wheel in wheels)
{
wheel.motorTorque = torque;
}
Debug.Log(GetComponent<Rigidbody>().velocity);
}
Now, when the train starts moving, it does it great until reaching the end of each rail piece. In that moment it stops like it's crashed with a wall, unless the speed is enough to make the train go beyond the collision, but still colliding.
This is showcased here: https://www.youtube.com/watch?v=PMf2rV2KnHc
Any ideas of what is causing such behaviour or any ideas on how to solve it?
Thanks!
Answer by huberthetman9 · May 07 at 10:58 PM
In that case, applying collisions and physics would be a bad choice. A better way would be to place markers above the tracks and command the vehicle to follow them. sorry for my English
I see. It's a good approach I didn't think of, for some reason lol.
However in this case I should also program the braking physics, wheel slip, etc, which is why I decided to ho with physics, so I could use what's already there.
Thanks!
Your answer
