- Home /
[C#] Wall Bounce While Setting Velocity for a Racing Game?
I'm trying to get my player vehicle to bounce slightly off the walls of the course when collision occurs. It would be simple, but my problem is I'm setting velocity every frame to accommodate for increases/decreases in speed tied to the press of a button. I can't have the velocity being applied through AddForce because when I turn the vehicle doesn't turn right away if I don't have the drag turned up high, and then when I have the drag up high wall bounces don't work either. Attached is a snippet of the vehicle script that I've been using. Any help is much appreciated.
if (Input.GetButton("Move") && timeHold < maxSpeed) {
timeHold += Time.deltaTime;
} else if (timeHold > 0f) {
timeHold -= Time.deltaTime * 2;
}
if (timeHold > maxSpeed) {
timeHold = maxSpeed;
}
if (timeHold > 0f) {
rb.velocity = (timeHold * accelleration) * transform.forward;
} else {
rb.velocity = 0 * transform.forward;
}
transform.Rotate(transform.up, handling * Input.GetAxis("Horizontal") * Time.deltaTime, Space.World);
Your answer
Follow this Question
Related Questions
Projectile isn't reaching my target. 1 Answer
Is there a way to lock velocity? 3 Answers
Player slows down when jumping/velocity changes 1 Answer
Distribute terrain in zones 3 Answers
Can't clamp velocity 3 Answers