|
i am in the progress of making a space game in unity. i have gotten quite a ways into it and have had few problems. my goal is to have the front of the ship always look or aim at where the user places his or her mouse and i want it to rotate along one axis. i have a script on my camera object that carries this function out but i know now that th ship will not rotate fully because of a gimble lock. i have been thinking about how to fix this and tried a few things but none have proved to fix the problem. i am very interested in finding a way to fix this. if anyone knows how to fix this or an alternative method to reach my goal i would greatly appreciate it. thank you so much
(comments are locked)
|
|
It looks to me that you're clamping your mouse position between -89 and 89 pixels (as seen on screen). I'm assuming you wanted to clamp the angle it's facing between the same range instead? Also, vs you're assigning to mouseZ but trying to use mouseY. You can restrict the rotation to X axis fixing the Y coordinate of worldPos. If you do this: your spaceship will be kept completely horizontal. If you want it to incline a little to the ground, just subtract some constant value from worldPos.y before fpc.transform.LookAt.
Jun 19 '11 at 12:34 AM
aldonaletto
(comments are locked)
|
|
thank you so much that fix the problem completely. i have been working on this for a month or so now. thanks, if anyone wants the completed script that fixed the problem it is right here: //attach this script to your camera and drag your character GameObject in the fpc slot in the inspector private var worldPos : Vector3; private var mouseX : int; private var mouseY : int; private var cameraDif : int; var fpc : GameObject; function Start () { } function Update () { }
(comments are locked)
|

If you could post your current code, it would help.
[code added to post]
Ok, so you're locking when you do what?
the spaceship which i want to rotate towards the mouse. only turns 180 degrees (not even that much). it faces downward (nose of ship pointing towards bottom of screen) and from there will only rotate 90 degrees to the left or right.
One somewhat off-topic comment: would you please remember to approve the correct answer on the questions you ask? Looking through your previous entries, you haven't accepted a single one as a solution.
It will help people with similar problems find their solution faster if you acknowledge that someone's provided a solution to you.