- Home /
Question by
CNuttall · Feb 18, 2018 at 11:10 AM ·
strange ioc
How to make a script slow down to a stop
How would I make this rotating script slow down to a stop? Many Thanks Charles
using UnityEngine;
using System.Collections;
public class SpinLogic : MonoBehaviour {
float f_lastX = 0.0f;
float f_difX = 0.5f;
float f_steps = 0.0f;
int i_direction = 1;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
f_difX = 0.0f;
}
else if (Input.GetMouseButton(0))
{
f_difX = Mathf.Abs(f_lastX - Input.GetAxis ("Mouse X"));
if (f_lastX < Input.GetAxis ("Mouse X"))
{
i_direction = -1;
transform.Rotate(Vector3.up, -f_difX);
}
if (f_lastX > Input.GetAxis ("Mouse X"))
{
i_direction = 1;
transform.Rotate(Vector3.up, f_difX);
}
f_lastX = -Input.GetAxis ("Mouse X");
}
else
{
if (f_difX > 0.5f) f_difX -= 0.05f;
if (f_difX < 0.5f) f_difX += 0.05f;
transform.Rotate(Vector3.up, f_difX * i_direction);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612152849im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Avoiding Bloom Pop 1 Answer
Enabling disabling objects via raycast 0 Answers
How to create an Animated 2D Line to help the user aim and shoot? 0 Answers
Compiler failed to execute. 1 Answer
build VR samples for android 0 Answers