Boosting player speed permanently based on checkpoint position

I’m a newbie to Unity and C#, and am trying to make my first game level. It a simple game, where a player jumps over obstacles, much like a horse-riding obstacle course. The forward movement of the player is automatic, and isn’t controlled by a keystroke. At certain checkpoints in the level, the forward speed is supposed to boost permanently, making the game more difficult to play.

I need help in coding this speed boost event. I tried using ‘other.attachedrigidbody.AddForce’ on the checkpoint trigger, but its effect decays over time, it is not permanent.

Now, I am trying a new bit of script, but its not working and its not returning an error message. Perhaps I’m writing the syntax correctly, but using it at the wrong place? I would appreciate it if an experienced pair of eyes can figure out how to script this event correctly. Please refer to the image below:

I think the best way to approach this is to make another class called CheckPoint which will store the speed multiplier and will wait for OnTriggerEnter function to fire (You will need to attach a collider of course). Then if Player enters the CheckPoints collider than you grab collider information from the function and check if it is player if so than grab its PlayerMovement script attached to it and multiply it with checkpoints speed multiplier. Then you won’t need to hardcode values in your playerMovements fixed update method.

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CheckPoint : MonoBehaviour
    public float speedMultiplier = 1.5f; // For example by 50% speed increase

    bool HasBoosted = false; // Bool to check if already boosted, avoiding double boost if stays too long in the trigger

    void OnTriggerEnter(Collider obj) 
        if(obj.collider.tag == "Player" && !HasBoosted)
			PlayerMovement movement = obj.collider.GetComponent<PlayerMovement>();

			movement.moveSpeed *= speedMultiplier;

			HasBoosted = true;

And also I would recommend you to use RigidBody.MovePosition instead of translate because translate doesn’t care about physics calculations.

Thanks a lot for your reply and the script that you prepared for this solution.I have created a separate class for the checkpoint trigger, and applied the script, creating the reference to ‘Player.Movement’, as you’ve shown, but it doesn’t seem to work. I’m trying to replace the transform.translate with Rigidbody.MovePosition, but there is some error in the syntax, and I can’t find the solution in the API. Could you please take a look at the script and tell me what the correct way of writing this syntax is?