- Home /
How to increase Player speed at a checkpoint?
I am trying to increase my players speed at a checkpoint by X f. I have set the checkpoints with triggers but for some reason the speed increases with 20 instead of wanted 5.
Here is my Player Controller script (Removed some parts so it would not be so long, but they have nothing to do with this level thing)
using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public Rigidbody rb; public float speed = 10f; public float movementSpeed = 5f; public float xRange = 40.0f; public float maxHeight = 20.0f; public float minHeight = 0.3f; public Text countText; private int count;
void FixedUpdate()
{
//get the input for horizontal axis
float horizontalInput = Input.GetAxis("Horizontal");
//get the input for vertical axis
float verticalInput = Input.GetAxis("Vertical");
//update the position
transform.position = transform.position + new Vector3(horizontalInput * movementSpeed * Time.deltaTime, verticalInput * movementSpeed * Time.deltaTime, speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Level"))
{
speed += 5f;
}
}
Thanks for the help in advance..
Answer by AconitumNapellum · Dec 02, 2019 at 09:58 AM
Player probably triggers OnTriggerEnter 4 times, just put a Debug.Log() inside your OnTriggerEnter function and verify.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215554im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Checking for collision of another gameObject with another trigger 1 Answer
Cannot get collision to do anything 1 Answer
OnCollisionEnter not working 2 Answers
get collision info from main script? 1 Answer
Colliding with the tag of a Child Object 2 Answers