- Home /
Rotation Problem
Hi to all, i've created a script for rotating an object, but i don't understand why it dosn't work....
This is the script:
using UnityEngine;
using System.Collections;
public class RideDampfkarussell : MonoBehaviour {
GameObject teller;
float teller_rot;
void Awake()
{
teller = transform.Find("Corpo").gameObject;
teller_rot = 0.0f;
}
void Start()
{
}
void Update()
{
teller_rot = (teller_rot + Time.deltaTime * 30.0f) % 360.0f;
teller.transform.localEulerAngles = new Vector3(0.0f, teller_rot, 0.0f);
}
}
hope you can help me, paolo
Answer by Cataclysm Entertainment · Feb 05, 2014 at 06:27 PM
Hi, I have begun programming with unity for 3 years, so sorry if I will say, will be wrong. I think you have too complicated your script. If your rotation is like the earth rotation, you simply write that :
var rotateSpeedX = 1.0f // or what do you want
var rotateSpeedY = 1.0f // or what do you want
var rotateSpeedZ = 1.0f // or what do you want again :)
var rotatedGameObject : GameObject;
function Update () {
rotatedGameObject.transform.Rotate(Vector3(rotateSpeedX,rotateSpeedY,rotateSpeedZ);
}
You can, with this option, use all axis (x,y,z) to rotate your object in all possible rotations.
Good luck for programming. ;) May the Programmation be with you !
Sorry for my bad english, I'm french.
Don't worry, i'm italian ;) I've begun last year, but i'm a disaster.. however, your script doesn't work.. i don't understand why..
#pragma strict
function Start () {
var rotateSpeedX = 1.0f // or what do you want
var rotateSpeedY = 1.0f // or what do you want
var rotateSpeedZ = 1.0f // or what do you want again
var rotatedGameObject : GameObject;
}
function Update () {
rotatedGameObject.transform.Rotate(Vector3(rotateSpeedX,rotateSpeedY,rotateSpeedZ));
}
}
Buongiorno,
For javascript, and I think it's the same thing in c#, you don't have to write the variables on the start function, you can write outside. Expect if you want to create variables for a specifical action.
For this code, if you attached this of the rotated gameObject, you can remove the lines number 8 and the first word of the line 14.
So you have a code like that :
#pragma strict
var rotateSpeedX = 1.0f // or what do you want
var rotateSpeedY = 1.0f // or what do you want
var rotateSpeedZ = 1.0f // or what do you want again
function Update () {
transform.Rotate(Vector3(rotateSpeedX,rotateSpeedY,rotateSpeedZ));
}
If my code is wrong again : you can watch the video of "Formation Facile" on youtube http://www.youtube.com/watch?v=O54abdJ4ezw&list=PL1CE0910DDEC1E411∈dex=5
it's in french, but i use his code for rotation.
Your answer
Follow this Question
Related Questions
Prefab Character position/rotation resets 0 Answers
Skateboarding Rotation Problem 1 Answer
Script Problem 1 Answer
Rotation in animation problem 0 Answers