For those that are in the know - Line 36 might contain my problem.
Hey guys. I’ve been having a bit of trouble for the better part of the day with a control I’m trying to implement. I have a 3rd person camera set up, using a Orbit around the player, I’m trying to use a static cursor position (roughly centered on screen - and when I say static cursor position I’m talking about the 2D GUI AIMING texture, not the mouse… so I might be using wrong terms here.) and use ScreenToWorldPoint to get a position for my character to rotate to.
The reason for this is when the player draws his gun, and only then, the GUI2D Texture appears, and then from there I’m trying to get the 3D space for him to look at. I’ve tried to restrict the up/down motion and only have him face in the direction, but I can’t even seem to get this far.
What current happens is the player warps to some odd ball angle ( I’m assuming because I’m not getting the correct position I want) and also he still changes in axis’ that I thought I limited. The player also for the most part warps to face the screen…
//Aimer
public Texture2D aim;
//Link to character controller to determine if weapon is out
public ThirdPersonController WpnOut;
//Store if weapon is out, and update it.
private bool isWeaponOut;
//Aimer size up and down
private int aimW = 32;
private int aimH = 32;
//floats for storing mouse cords to make player look at (might change to int)
private float mouseX;
private float mouseY;
//character ref so we can make him face the mouse postiion
public GameObject player;
//Storage of the variable that character will look at
private Vector3 posToFace;
//make sure our character only looks along the correct axis
private float justTurn;
void Start () {
//ref to the AI script attacked for checking if weapon is out - if it is, over-ride current animations and use gun drawn animations.
isWeaponOut = WpnOut.wpnDrawn;
justTurn = camera.transform.position.y - player.transform.position.y;
}
void Update()
{
isWeaponOut = WpnOut.wpnDrawn;
//Debug.Log (isWeaponOut);
if(isWeaponOut)
{
//Right here might be my issue. How can I use the GUI 2D texture to project what I need to look at straight away from the camera?
mouseX = Input.mousePosition.x;
mouseY = Input.mousePosition.y;
posToFace = camera.ScreenToWorldPoint(new Vector3(mouseX,mouseY,justTurn));
player.transform.LookAt(posToFace);
}
}
void OnGUI()
{
if (isWeaponOut){
//Static method.
GUI.DrawTexture(new Rect(Screen.width/2 + 200,Screen.height/2,aimW,aimH), aim);
//Non-static aim'er following mouse.
//GUI.DrawTexture(new Rect(Input.mousePosition.x -16 ,Screen.height - Input.mousePosition.y -16, aimW, aimH), aim);
}
else{return;}