- Home /
how to make rotate relativeTo some GameObject
ok I've figured out how to set rotation around world or self but I kinda can't find to be relative to players rotation
so for example that Y always rotates away from me.
not towards me if I change the X rotation or Z
my code:
if (Input.GetKey(KeyCode.Mouse2)) {
ObjectX = (Input.GetAxis("Mouse X"));
ObjectY = (Input.GetAxis("Mouse Y"));
if (Input.GetKey(KeyCode.Delete)){ObjectZ = 1 ;}
if (Input.GetKey(KeyCode.PageDown)){ObjectZ = -1 ;}
transform.Rotate (ObjectY,ObjectX,ObjectZ,Space.World /*or Space.self*/);
}
it would be nice IF I could do
transform.Rotate (ObjectY,ObjectX,ObjectZ,Player.Rotate);
but it says that it cannot convert it
Assets/Craft/CraftScripts/CraftPosition.cs(47,43): error CS1503: Argument `#4' cannot convert `method group' expression to type `UnityEngine.Space'
I already know for Space.World if player's position is correct it'll always be correct but I want that I can change my position too and that it'll be correct
Answer by Kortekk · Jan 20, 2013 at 06:34 PM
If I understand the functionality you're trying to achieve correctly, you can try making your object's gameobject a child of your player and just using Space.self in your object's rotation code.
no it must not become a child of a object
because it's a craftable item and when it's crafted I want it to stay there for ever
but when crafting it I want to be relative to players rotation
Your answer