- Home /
Return to the point of rotation?
Hi,
I'm trying to spin one object with the cursor and when the spinning is finished, the object wait for 2 seconds and then return to the point or rotation.
The rotation is working but, the return to the point of rotation is not working.
Please take a look to my script any advice is welcome
Thanks in advance.
var rotationSpeed = 20; // rotation speed
var rotationStart = 0.0; // rotation on start
function Awake () {
transform.Rotate(rotationStart,0,0);
}
function Update (){
if (Input.GetButton("Fire1")){
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
if (Input.GetButtonUp ("Fire1")) {
yield WaitForSeconds (2.0);
transform.Rotate(rotationStart,0,0);
}
}
}
Answer by Lovrenc · Jan 15, 2013 at 04:08 AM
Try:
transform.rotation = Quaternion.Euler(rotationStart,0,0);
Your code complete:
#pragma strict
var rotationSpeed = 20; // rotation speed
var rotationStart = 0.0; // rotation on start
function Awake () {
transform.Rotate(rotationStart,0,0);
}
function Update (){
if (Input.GetButton("Fire1")){
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
}
if (Input.GetButtonUp ("Fire1")) {
StartCoroutine("Return",2);
}
}
function Return(){
yield WaitForSeconds (2.0);
transform.rotation = Quaternion.Euler(rotationStart,0,0);
}
Answer by paco morales · Jan 15, 2013 at 04:19 AM
Hi Lovrenc,
Thanks for your help, I made the change to the script but is not working, here it is my Updated script.
any advice?
Thanks again
var rotationSpeed = 20; // rotation speed
var rotationStart = 0.0; // rotation on start
function Awake () {
transform.Rotate(rotationStart,0,0);
}
function Update (){
if (Input.GetButton("Fire1")){
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
}
}
function Return(){
if (Input.GetButtonUp ("Fire1")) {
yield WaitForSeconds (2.0);
transform.rotation = Quaternion.euler(rotationStart,0,0);
}
}
Try to use comments for posts like this.
You have function Return now, but you never call it. this goes to update. You dont need Input.GetButtonUp in Return function.
if (Input.GetButtonUp ("Fire1")) {
StartCoroutine("Return",2);
}
Thanks again, but still not working :(
var rotationSpeed = 20; // rotation speed var rotationStart = 0.0; // rotation on start
function Awake () {
transform.Rotate(rotationStart,0,0);
}
function Update (){
if (Input.GetButton("Fire1")){
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("$$anonymous$$ouse X") * rotationSpeed);
}
if (Input.GetButtonUp ("Fire1")) {
StartCoroutine("Return",2);
}
}
function Return(){
yield WaitForSeconds (2.0);
transform.rotation = Quaternion.euler(rotationStart,0,0);
}
Now its working perfectly !! $$anonymous$$any Thanks :)
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Slowing velocity in Rotation? 1 Answer
please help! Game Spinner 0 Answers
Simple rotation script. (loop) 3 Answers
Spin a 2D object with mouse drag 2 Answers