# Look at mouse problem

 0 I hava a problem i am making a Top Down game and i have a space ship that has a turret on top i have this script to make the turret look at he mouse position ``````private var worldPos : Vector3; private var mouseX : int; private var mouseY : int; private var cameraDif : int; var fpc : GameObject; function Start () { //determines how far down the ScreenToWorldPoint is from the camera position //it's calculated [height of camera] - [height of pivot point of character] //this is to ensure the character only rotates (via LookAt) along rotation.x and doesn't look up or down cameraDif = camera.transform.position.y - fpc.transform.position.y; } function Update () { mouseX = Input.mousePosition.x; mouseY = Input.mousePosition.y; //this takes your current camera and defines the world position where your mouse cursor is at the height of your character -->translates your onscreen position of mouse into world coordinates worldPos = camera.ScreenToWorldPoint(Vector3(mouseX, mouseY, cameraDif)); fpc.transform.LookAt(worldPos); } `````` I attacked this to the camera and the fpc is set as the turret but when i play the game my turret also looks up and down i only want it to look around can someone please help? Thanks. more ▼ asked Apr 20 '11 at 11:46 PM Aydan 180 ● 28 ● 37 ● 47 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 This might work if I understood your question well: `````` worldPos = camera.ScreenToWorldPoint(Vector3(mouseX, mouseY, cameraDif)); var turretLookDirection:Vector3 = Vector3(worldPos.x,fpc.transform.position.y, worldPos.z); // here instead of Y value you might put something which suites your game better fpc.transform.LookAt(turretLookDirection); `````` Now it should only rotate around, and not looking up/down. more ▼ answered Apr 21 '11 at 12:39 AM Kourosh 1.5k ● 47 ● 53 ● 65 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x198
x172
x162
x69
x49

asked: Apr 20 '11 at 11:46 PM

Seen: 1705 times

Last Updated: Apr 20 '11 at 11:46 PM