Hello Unity Community,
I have a script that has an object accelerate but my problem is that it accelerates to fast. How can I slow down the acceleration? I figured I could do something with the modulus operator but I can’t seem to figure it out. Here’s my code:
using UnityEngine;
using System.Collections;
public class MoveForward : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
public int i;
public int MaxSpeed = 500;
public int MinSpeed = 5;
// Update is called once per frame
void FixedUpdate () {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), (2*i)/100);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
if (i < MaxSpeed){
i++;
print (i);
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
The i variable is what’s making the object accelerate. The i with the if statement is where I need to put my code for slowing down acceleration. Any help by you fine folks is appreciated.