- Home /
How to move a Transform on top of a series of Transforms
I have script that instantiates a series of Transforms which is the road a car is supposed to drive on. The problem I'm having is that even if the road consists of equal transforms, with only their z-axis position differing the car object seems to collide with the sides of the cubes instead of moving smoothly on top of them.
The way I generate the road is simply an empty GameObject the following script attached (Where roadPiece is a prefab of a cube):
void FixedUpdate () {
Instantiate(roadPiece, transform.position, transform.rotation);
}
The parent then moves around and the road that is shaped looks fine.
The car object moves around with the following script:
void FixedUpdate () {
if (Input.GetKey(KeyCode.W)){
rigidbody.AddRelativeForce(transform.forward*acceleration,ForceMode.Acceleration);
}
if (Input.GetKey(KeyCode.S)){
rigidbody.AddRelativeForce(-transform.forward*deceleration, ForceMode.Acceleration);
}
}
How do I keep the car object from bumping into the cubes of the road and just move on top of them instead?
Your answer
Follow this Question
Related Questions
Stop a enemy by pointing a light at it. 4 Answers
My character isn't moving 0 Answers
Ai Prefab Spawning in Without a target? 1 Answer
Semi Dynamic Shadows 1 Answer
Transform.Position stop? 1 Answer