using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spin : MonoBehaviour
{
public float speed;
public float RotationSpeed = 1;
public float RotationAcceleration = 1;
private float currentRotationSpeed;
// Start is called before the first frame update
void Start()
{
currentRotationSpeed = RotationSpeed;
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, 0, speed * Time.fixedDeltaTime, Space.Self);
if (Input.GetKeyDown("w") || Input.GetKeyDown("s"))
{
currentRotationSpeed = RotationSpeed;
}
if (Input.GetKey("w"))
{
transform.Rotate(0, 0, currentRotationSpeed, Space.Self);
currentRotationSpeed += Time.fixedDeltaTime * RotationAcceleration;
}
if (Input.GetKey("s"))
{
transform.RotateAround(transform.position, transform.up, currentRotationSpeed);
currentRotationSpeed += Time.fixedDeltaTime * RotationAcceleration;
}
}
}
I tried to remove this line : the line is just for testing automatic rotation.
transform.Rotate(0, 0, speed * Time.fixedDeltaTime, Space.Self);
in any case when i'm pressing the w key without leaving the key it's rotating and the speed is increasing but at some point the speed slow down and then before stop it's changing the rotation direction and start increasing the rotation speed again.
i want that when pressing the w key increase the speed up nonstop then when pressing the s key decrease the speed rotation from the current point slowly down to stop.
and then when pressing w it will start increasing the speed again and s slow down to stop smooth.