Hello, all! I am trying to move a cube with mouse movement.
Left and Right, and Up and Down.
When I try to do this it stays in a small bounding box, as well as clips through the ground.
My game needs the player (cube) to avoid incoming objects and obstacles (including the floor)
using UnityEngine;
using System.Collections;
public class MouseControl : MonoBehaviour {
// Mouse Control Variabbles
public float mouseSensitivityX = 1;
public float mouseSensitivityY = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float moveLR = Input.GetAxis("Mouse X") * mouseSensitivityX * Time.deltaTime;
float moveUD = Input.GetAxis("Mouse Y") * mouseSensitivityY * Time.deltaTime;
Vector3 mouse = Camera.main.ScreenToViewportPoint(Input.mousePosition);
transform.position = new Vector3(mouse.x, mouse.y, transform.position.z);
//Camera.main.ScreenPointToRay(Input.mousePosition);
//Vector3 mouse = Input.mousePosition;
//mouse = mouse;
//transform.position = Camera.main.ScreenToViewportPoint(mouse);
}
}
The commented out sections are from previous attempts at my problem.
Many thanks guys and girls.