- Home /
Ignore an axis in Quaternion.Slerp || move ship
Hi, i'm trying to move a spaceship for a multiplayer game. The camera will be first person, but the ship also has to tilt and rotate because the other players can see it. When i press a horizontal button or move the mouse in the horizontal axis the ship should tilt (and get back in the original position after the button is released). If the ship is moved by the mouse is also should rotate around the vertival axis (it should look in the direction it moves).
My code looks like this:
//Rotate ship with Mouse Y Axis ship.transform.Rotate(0,Input.GetAxis("Mouse X") * Time.deltaTime * 1000,0);
//Tilt ship var tiltAroundX = (Input.GetAxis("Horizontal") + (Input.GetAxis("Mouse X")75)) horizontalTiltAngle; var tiltAroundZ = Input.GetAxis("Mouse Y") -75 verticalTiltAngle; var target = Quaternion.Euler (tiltAroundX, 0 , tiltAroundZ); // Dampen towards the target rotation ship.transform.rotation = Quaternion.Slerp(ship.transform.rotation, target, Time.deltaTime * 2.0);
This code is in the Update Method. Now the problem is, that i rotate the ship around the y axis, but because of the "Slerp" it moves back again. Is there any other way to make my ship look in the direction my camera looks and is it possible to ignore the y axis in Quaternion.Slerp? Does somebody knows a "SpaceShipController" or anything similar?
Thanks a lot!
Your answer
Follow this Question
Related Questions
first person controller prefab 6 Answers
Changing First person look 0 Answers
1st person arms still clipping with near plane 0.01 2 Answers
How do I make my fps character grab objects? 4 Answers
Move Object - doesn't work 0 Answers