- Home /
How to make something rotate faster and faster
I have an orb in my game and it rotates 25 degrees per second from a script but I want to make so it can attack and I want it to go faster and faster after every second so it "charges" itself how would you approach that?
Answer by metalted · Jul 04, 2019 at 06:00 PM
Save the rotational speed to a variable, then add a certain amount to that variable every second. Apply rotation to object.
public float originalRotationSpeed = 25f;
public float rotationIncrement = 1f;
public bool incrementRotation = false;
public float currentRotationSpeed;
public void Start()
{
ResetRotation();
}
public void ResetRotation()
{
currentRotationSpeed = originalRotationSpeed;
}
public void Update()
{
float delta = Time.deltaTime;
transform.Rotate(0, currentRotationSpeed * delta, 0);
if(incrementRotation)
{
currentRotationSpeed += rotationIncrement * delta;
}
}
I just added it but there is one thing it doesn't look like it goes faster and faster in the rotation how do I fix that?
The script is setup as follows: The values represent the initial rotation speed and the amount to add to the rotation each second. The boolean is used to increment the rotation or not, this depends on what you need. $$anonymous$$aybe you don't want to speed up rotation right away or you want to stop increasing the rotation speed at some point. You can set the bool to true or false for that. ( If it is not increasing now, maybe it is because the bool is still set to false? ) In Start() we reset the rotation. Resetting does nothing more than assign the original speed to the current speed. The object will now rotate slowly again. If we don't do this in Start(), the currentRotationSpeed will default to 0. So we either have to use Start() or already assign a value to currentRotationSpeed. In Update() we get the deltaTime value and apply the rotation to the object. If the bool is true, increase the rotation. If it is false, the rotation will stay the same at 25.
I tried to change some things in the script and even if I change the originalRotationSpeed it still goes the same I tried to change it from 25f to 100f and it rotates at the same speed
Your answer
