Position Targetting.
O.K. So I have been looking over so many of the "solutions" here trying to get a straight answer. I am trying to keep the movement of the player using mouselook direct on point to lock the view to that position and not slide here and there all over the screen.
When i see others asking this such as cursor lock to position, all I am finding is turning the pointer on or off locking it to visible or invisible. That is not the "lock position" people are asking about or myself.
Simply put I and others need to know how to "Lock the position" so that where you are pointing on the screen in the game is where you are pointing such as shooting a gun, and not sliding all over the place.
now, i have tried others and finally came to compile this code.
using UnityEngine;
using System.Collections;
public class MouseLook : MonoBehaviour
{
public float LookSensitivity = 0.0f;
public float xRotation;
public float yRotation;
public float currentXRotation;
public float currentYRotation;
public float xRotationV;
public float yRotationV;
public float lookSmoothDamp = 0.0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
yRotation += (Input.GetAxis("Mouse X") * LookSensitivity);
xRotation -= (Input.GetAxis("Mouse Y") * LookSensitivity);
xRotation = Mathf.Clamp(xRotation, -90, 90);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
}
If i turn the dampening up or down it still causes a sliding effect rather than smooth movement. The sensitivity change makes it so ridiculous that I sneeze and i spin out of control. About the only part of the code working right is keeping the position from going over a 90 degree range.
So any suggestions?
Your answer
Follow this Question
Related Questions
Problems with positioning game objects 0 Answers
Understanding relationship between scale and position 0 Answers
How to random place sprites but make sure they aren't touching? 1 Answer
How can I correctly generate Button objects with C# script? 1 Answer
Moving an image on the X axis is not working as it should. 0 Answers