- Home /
RotateAround a player
I am working on making a zelda-type game, and i am trying to make a script to make the sword swing. I am using the transform.RotateAround function, and I can't get it to work. Nothing happens. It deletes the sword clone after 1 second, but nothing happens before that, I don't even see the object appear in my game window, when it does in the hierarchy.
void Update () {
if(Input.GetKeyDown("x")){
var P = (GameObject)Instantiate(sword,transform.position,Quaternion.identity);
P.transform.parent = transform;
// Spin the object around the world origin at 20 degrees/second.
transform.RotateAround(transform.position, Vector3.up, -180);
// Destroys the swords created after one second
// of creation, in order of creation
GameObject[] killEmAll;
killEmAll = GameObject.FindGameObjectsWithTag("Sword");
for(int i = 0; i < killEmAll.Length; i++){
Destroy(killEmAll[i].gameObject, 1);
}
}
}
}
you are rotating player as i can understand from the code, you should rotate p.transform, not transform.
Also rotation is not being done over time, it will be a single flip (sort of). you can add a counter or use invoke function to see its rotation.
you are rotating player as i can understand from the code, you should rotate p.transform, not transform.
Also rotation is not being done over time, it will be a single flip (sort of). you can add a counter or use invoke function to see its rotation.
How do I do that? I tried changing it to transform.RotateAround(transform.position, Vector3.zero, -180, 1); and it gave me an error.
Answer by guido123 · Apr 01, 2014 at 11:38 AM
you should rotate P which is the sword. also multiply rotation speed by the time the frame took to render (Time.deltaTime) it should look something like this:
P.transform.RotateAround(transform.position, Vector3.up, 20*Time.deltaTime);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Transform.RotateAround / Obsolete / solution? 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
RotateAround Limitations 2 Answers