- Home /
Question by
RGI · Aug 09, 2013 at 03:50 PM ·
rotationjavascripttransformrotate object
Object not rotating
Hi, Iam using this simple script for rotating an object but for some reason it isnt rotating. Instead it turns only from any point to 180 and then stops rotating. here is the script:
var speed = 0.1;
function Update () {
transform.rotation.z = transform.rotation.z + speed;
}
If I change the rotation to position, the script works so what is it?
Comment
If you're wanting to rotate something continuously at a certain speed, google the Unity Script Reference. Once you're there, search for localEulerAngles. I'll give a basic example that will do this attach this script to any object you want to rotate.
using UnityEngine;
using System.Collections;
public class Example : $$anonymous$$onoBehaviour
{
float rotationSpeed = 120.0f;
Vector3 axis = Vector3.up;
void Update()
{
transform.localEulerAngles += axis * rotationSpeed * Time.smoothDeltaTime;
}
}
If you wish to do this in JS:
#pragma strict
var rotationSpeed : float = 120.0f;
private var axis : Vector3 = Vector3.up;
function Update()
{
transform.localEulerAngles += axis * rotationSpeed * Time.smoothDeltaTime;
}
Best Answer
Answer by IgorAherne · Aug 09, 2013 at 04:00 PM
#pragma strict
var speed :float = 20.0;
function Update(){
transform.Rotate(0,0, speed*Time.deltaTime);
}