Third-person view developing

Normally,binding camera with Player into Third-person view equals to let camera be Player's child ,but in our case the Player moving way is rolling ,so the camera will roll with player ,which is not expected

write a script to get and set camera offset relative to Player

declare GameObject instance to bind Player
then declare a vector3 var to store offset

1
2
public GameObject player;
private Vector3 m_Offset;

at start function,store initial offset

1
2
3
4
5
void Start()
{
m_Offset = transform.position - player.transform.position;
// m_Offset = this.transform.position - player.transform.position;
}

then after Player moved,calculate frame(relative to physical system)

1
2
3
4
void FixedUpdate()
{
transform.position = player.transform.position + m_Offset;
}
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2019-2024 kier Val
  • Visitors: | Views: