Hey there everyone,
I’ve ran in to a problem: I have a Prefab that follows my mouse and I am trying to rotate it (around the Y-axis). I’ve looked everywhere and tried everything but my prefab keeps spinning around in big circles (not around the Y-axis).
This is my current rotation code:
if(Input.GetKey(KeyCode.R)){
Instance.transform.Rotate(0,10,0);
}
`
Is anyone able to help me out?
Note: the script is attached to my camera, I think it might have something to do with this (?)
`
Edit: I fixed the script that causes my object to follow the cursor, it’s working properly now. Thanks all!
So it wouldn't be possible to have it on a different object?
– LemondragonYou can, but you have to reference the game object you are spinning. Lets say the object you want to spin has the name 'Player', you could do: var player : Transform; function Start() { player = GameObject.Find("Player").transform; } function Update() { if(Input.GetKey(KeyCode.R)){ player.Rotate(0,60.0 * Time.deltaTime,0); } }
– robertbuI am using the following code to reference the GameObject. <pre>public GameObject Instance;
– Lemondragonand</pre><pre> Instance = Instantiate(InstancePrefab, camera.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity) as GameObject;<code></pre></code>Then the rotation code would be: function Update() { if(Input.GetKey(KeyCode.R)){ Instance.transform.Rotate(0,60.0 * Time.deltaTime,0); } }
– robertbuIt does not seem to work. I get the same result as always: http://i.imgur.com/U1hHxvU.gif It just starts making circles.
– Lemondragon