- Home /
Use MoveRotation to Look At Another Object
Basically I am looking for a simple way for using the rigidbody/physics engine to have my ship look at another object (the enemy). I figured getting the direction between my transform and the enemy transform, converting that to a rotation, and then using the built in MoveRotation might work but it is causing this weird effect where it just kind of tilts the ship. I posted the bit of code as well as images of before and after the attempt to rotate the ship (The sphere is the enemy).
private void FixedUpdate()
{
//There is a user on the ship's control panel.
if (user != null)
{
var direction = (enemyOfFocus.transform.position - ship.transform.position);
var rotation = Quaternion.Euler(direction);
ship.GetComponent<Rigidbody>().MoveRotation(rotation);
}
}
Before. After.
Your answer
Follow this Question
Related Questions
Rolling a 3D triangle 0 Answers
Help making orbiting planets,How to rotate around the objects with the largest mass? 0 Answers
How to set a limit for my player rotation ? 0 Answers
How to make an object(cylinder) always at the center of an object(Terrain)? 0 Answers
Balancing in a bike game 0 Answers