Hello,
I am trying to make a simple game, but I ran in to the same problem a few times now.
I want a power up which would increase the speed, but I want the speed to increase over time. Currently it increases the speed instantly no matter what I try to do, and I also will want the speed to degrade over time back to the default speed. PLEASE HELP
This is my player controller.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float turnSpeed;
public float fallSpeed = 14f;
public float multipliedSpeed = 0f;
private Rigidbody rb;
private float currentSpeed;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
currentSpeed = Mathf.SmoothStep(fallSpeed, (fallSpeed + multipliedSpeed), 5f);
Vector3 movement = new Vector3((h * turnSpeed), -currentSpeed, 0.0f);
rb.velocity = movement;
}
}
This is my Power Up
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUp : MonoBehaviour {
public float multiplier = 10f;
private PlayerController playerController;
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Player"))
{
PickUp(other);
Destroy(this.gameObject);
}
}
void PickUp(Collider player)
{
player.GetComponent<PlayerController>().multipliedSpeed += multiplier;
}
}