Question by
LordGeezmo · Jan 15, 2016 at 04:55 PM ·
c#3dtop-down
Make 3D object point to cursor
I've searched everywhere on google, and all the answers come up with either non-functional code, error code or code meant for 2D worlds.
I've already made a camera pointing top-down at the object, and I suspect that I have to use the ground in order to point the object in the right direction.
I currently use this simple code to move my character around, I need to replace the (Input.GetKey(KeyCode.E)) and (Input.GetKey(KeyCode.Q)) so that my character can be even close to controllable, currently it handles as easily as the camera in Majoras Mask :{.
So I basically need the playerchar to be able to look at where the mouse is.
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.back * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.E))
{
transform.Rotate(Vector3.up * 50 * Time.deltaTime);
}
if (Input.GetKey(KeyCode.Q))
{
transform.Rotate(Vector3.down * 100 * Time.deltaTime);
}
If someone could link me to a tutorial that explains how to do this that would be great
Comment