- Home /
Align Rigidbody on Rail?
hello! i just wanted to create a small carrera rc tack car kinda game. but i stuck at the part where the car should drive in a curve. the code looks simple as this:
using UnityEngine;
using System.Collections;
public class Carrera : MonoBehaviour {
public float accerleration;
void Update () {
if (Input.GetKeyUp(KeyCode.DownArrow)) {
this.gameObject.GetComponent<Rigidbody>().AddForce(this.gameObject.transform.forward * accerleration, ForceMode.Acceleration);
}
if (Input.GetKey(KeyCode.DownArrow)) {
this.gameObject.GetComponent<Rigidbody>().AddForce(this.gameObject.transform.forward * -accerleration, ForceMode.Acceleration);
}
}
}
but the problem with this is that: https://gfycat.com/PlayfulThoughtfulBluejay
i somehow have to tell the rigidbody that he should rotate to the left in the curve or something like that. but how?
Try experimenting with the friction values for the wall material, so that the character can slide along.
https://docs.unity3d.com/$$anonymous$$anual/class-Physic$$anonymous$$aterial.html
thanks. that helps already a bit. put still the capsule wont rotate along the track https://gfycat.com/HonoredPoorInsect
One way of doing this would be to cast a ray out sideways from your "rc car" and rotate it according to the surface normal of the wall.
hey, sounds like a good aproach. i know how to raycast stuff but not entirely sure how to check and rotate the car
Your answer
Follow this Question
Related Questions
Problem with Rigidbody control script! (collision with perpendicular walls problem) 1 Answer
How can i make my RigidBodyFPSController to move when Is Kinematic is true ? 1 Answer
Player can't interact certain Rigid Body while another rigid body can. 0 Answers
Can't set position of Rigidbody precisely 0 Answers
Rigidbody acting different on two different objects 1 Answer