Thursday, March 10, 2016

Dev report and Unity 3D rotation script

Hi!
I have to tell you two things. Firstly,  I am texturing the land driller boss. It's unwrapped and now is going to get some fresh paint. Secondly, I have got brand new script for you:

using UnityEngine;
using System.Collections;

public class AnimationRotator : MonoBehaviour
{

public bool useRigidbody; // chech this if you want to apply rotation force to a rigidbody
public Rigidbody rig; // attach rigidbody you want to constantly rotate

public Vector3 rotationSpeed; // set rotation speed for individual axes
public float rotConst = 50f; // speed multipler for non rigidbody rotation


void Start()
{
if (useRigidbody)
{
rig = GetComponent<Rigidbody> ();
rig.angularVelocity = rotationSpeed;
}
} // this part is designed to apply rotation force to a rigidbody (if rigidbody has some angular drag, it will stop after some time)

void Update()
{

if (!useRigidbody)
{
transform.Rotate (rotationSpeed.x * Time.deltaTime * rotConst, rotationSpeed.y * Time.deltaTime * rotConst, rotationSpeed.z * Time.deltaTime * rotConst);
}
// this rotation is non-rigidbody, it constantly rotates object around designed axes

}
}

No comments: