- Home /
How to make an object rotate on the y axis towards the mouse?
I am new to this and I have tried everything i can come up with but it either dosent work or rotates on a different axis.
function Update () { var pos = transform.position;
var follow = Input.mousePosition; var rotate = Quaternion.LookRotation(follow-transform.position); //transforms vector3 coordonates into quaternion degrees //transform.rotation=Quaternion.Slerp(transform.rotation,rotate, 2.1); //transform.position=Vector3.RotateTowards(transform.position,follow,3.1,1.2); //transform.rotation=Quaternion.FromToRotation(pos,follow);
}
I want to achieve this without using the GetAxis from the input.I want to see if it is possible if not a very simple example would be appreciated.Tried everything from quaternion to vector3.The examples above are the methods that I have tried plus some others but none work the way that I need.Help, explanation and an example would be appreciated.
Answer by DenverCoulson · Aug 31, 2012 at 09:19 PM
I think you will need to explain a little better as to what you are trying to do and thenhow you want this to rotate. Input.mousePosition is going to return you a Vector2. A rotation around the y axis is 3 dimensional. You need to convert your Input.mousePosition into a proper 3-dimensional position (aka convert your 2D position on to a specified 3D plane. This is not an actual plane, it would be function you would determine that equates to a plane).
Answer by Nk.Andrei · Sep 01, 2012 at 01:54 PM
I want to make an object rotate along the y axis towards the mouse position.I want to know if this is possible and if yes then how. Instead of transforming a 2d mouse position into a 3d one I could just make a cube or something follow the mouse pointer. An example and an explanation would be greatly apprciated.Im really stuck here.
....a cube would be in 3D space so it would do exactly the same thing as converting mouse position into three dimensional coordinates. Draw a picture or something because right now what you want to do makes no sense.
Answer by Nk.Andrei · Sep 01, 2012 at 01:54 PM
I need the simplest way possible to achieve this.Just rotate an object on the y axis to follow the mouse(rotate towards the mouse on the y axis).I need something simple.
Your answer
Follow this Question
Related Questions
Rotate and Move towards Mouse Point 0 Answers
3D Turret Rotation 0 Answers
Freeze Camera Rotation that is attached to the object in certain moments 0 Answers
TurretRotation on a starship (full 3d) 3 Answers
2d turret problem 1 Answer