- Home /
Move Object - Mouse Input Y Axis from Camera
Hi, i'm working on a tps game ... right now i'm working on the hip fire aiming mecanism that uses mecanim offcourse for animation process...
However i'm riddling my self with a simple problem.... I do not want to use the camera to create a 3d target from camera to world space not what i'm trying to achieve ...
To make things simple I have a cross hair object that is parented to the main player object that controlls the player's movement based on mouse input * damping and sensitivity values...
So the idea is to have this 3D cross hair fallow the visual 2D one that uses a mouse controller input script...
Here is the crossHair script...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CrossHair : MonoBehaviour {
[SerializeField]Texture2D image;
[SerializeField]int size;
[SerializeField]float maxAngle;
[SerializeField]float minAngle;
[SerializeField]float targetDistance;
public float lookHeight;
public Transform cross_target;
public void LookHeight(float value)
{
lookHeight += value;
if (lookHeight > maxAngle || lookHeight < minAngle)
lookHeight += value;
}
void LateUpdate()
{
//this is where the cross_target Transform code should go
//this is only move along the y position then rotates with player movement
}
void OnGUI()
{
Vector3 screenPosition = Camera.main.WorldToScreenPoint (transform.position);
screenPosition.y = Screen.height - screenPosition.y;
GUI.DrawTexture(new Rect(screenPosition.x, screenPosition.y - lookHeight, size, size), image);
}
}
and to give you a idea as to some placement where the actual mouse input is modified.... is here...
void LookAround ()
{
mouseInput.x = Mathf.Lerp (mouseInput.x, playerInput.MouseInput.x, 1f / MouseControl.Damping.x);
mouseInput.y = Mathf.Lerp (mouseInput.y, playerInput.MouseInput.y, 1f / MouseControl.Damping.y);
transform.Rotate (Vector3.up * mouseInput.x * MouseControl.Sensitivity.x);
CrossHair.LookHeight (mouseInput.y * MouseControl.Sensitivity.y);
//playerAim.SetRotation (mouseInput.y * MouseControl.Sensitivity.y);
}
So ideally the new 3D transform should just move along the with the look height parameter of the CrossHair script however i'm having major problems I've tried taking the screenPosition Vector3 values then declaring a new vector 3 that converts it back to world space and use only that newly vector3 y value....
I highly appreciate the feedback in advanced , Thank you
So basically move the 3d cursor with the 2D one sorry.