- Home /
Question by
guyschroeder2001 · Apr 21, 2021 at 12:40 PM ·
speedracing
Speed Boost doesn't work
Hi, I want to boost the speed of the car if it collides with the box. it collides correctly and the box is also destroyed but the boost does not work. (Like in Mario Kart for example but instead of an item just a boost) Can anyone help? Thanks!
void Start()
{
speed = 1;
boosttimer = 0;
boosting = false;
}
void Update()
{
mouv.x = 0;
mouv.y = 0;
mouv.z = Input.GetAxis("Vertical");
r = Input.GetAxis("Horizontal");
if (boosting)
{
boosttimer += Time.deltaTime;
if (boosttimer>=15)
{
speed = 12;
boosttimer = 0;
boosting = false;
}
}
}
//item
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Box"))
{
boosting = true;
speed *= 5f;
Destroy(other.gameObject);
}
}
//mouvement
void FixedUpdate()
{
Debug.Log(speed);
Vector3 newPosition = rb.position + transform.TransformDirection(mouv * speed * Time.fixedDeltaTime);
rb.MovePosition(newPosition);
transform.Rotate(0, 2 * r, 0, Space.Self);
}
//Speed OnRoad/OffTerrain
private void OnCollisionStay(Collision other)
{
if (!other.gameObject.CompareTag("Road"))
speed *= 0.9f;
if (speed < 7f)
{
speed = 7f;
}
if (!other.gameObject.CompareTag("Plane"))
speed = 12;
}
}
Comment
Your answer
Follow this Question
Related Questions
Smoother lerp at fast speeds? 0 Answers
Flight Sim Control 1 Answer
Pathfinding with specific end-direction and turning speed limit 0 Answers
How do change my characters speed? 1 Answer