[英]Unity 3D - Third Person character movement using rigidbody
I am new to Unity trying to make my first game (a Third Person Shooter). 我是Unity的新手,试图制作自己的第一款游戏(《第三人称射击》)。 It's been now more than a week that I've tried again and again to get my character moving using a rigidbody component and NOT the Character Controller or the simple transform.Translate.
现在已经有一个多星期了,我一次又一次地尝试使用刚体部件而不是角色控制器或简单的transform.Translate来使角色移动。
I have had about 30 web pages opened since a week browsing topics about it but I haven't found anything (almost made me feel like I am trying to do something impossible lol...). 自一周以来,我已经打开了大约30个网页,浏览有关该主题的信息,但是我什么也没找到(几乎让我觉得我正在尝试做一些不可能的事情……)。
So, I want to move my character just like in Splinter Cell Blacklist, and to have the camera with the crosshair controlled by the mouse (if I shoot, the character would rotate if not facing the target and then shoot). 因此,我想像在“分裂细胞黑名单”中那样移动角色,并用鼠标控制带有十字准线的摄像机(如果我拍摄,角色会在不面对目标的情况下旋转然后拍摄)。
For the movement, if it is not possible with the rigidbody then I'll use one of the others, it's just that I love the real feeling that the rigidbody has. 对于运动,如果不能使用刚体,那么我将使用其中之一,只是我喜欢刚体所具有的真实感觉。
If there's even a tutorial that break it down to really understand, that would be great or just some code with comments (I have a C# background). 如果甚至有一个将其分解为真正理解的教程,那将是很棒的,或者只是一些带有注释的代码(我有C#背景)。
float moveSpeed = 6f; // Player's speed when walking.
float rotationSpeed = 6f;
float jumpHeight = 10f; // How high Player jumps
Vector3 moveDirection;
Rigidbody rb;
// Using the Awake function to set the references
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
Move();
}
void Move ()
{
float hAxis = Input.GetAxis("Horizontal");
float vAxis = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(hAxis, 0f, vAxis);
rb.position += movement * moveSpeed * Time.deltaTime;
}
My idea. 我的点子。 If you want the real feel, you need the
rigidbody.addforce
to your character at the proper part of the character body. 如果您想要真实的感觉,则需要在角色身体的适当部位为您的角色添加“
rigidbody.addforce
。 Not the rigidbody.position
. 而不是
rigidbody.position
。
Hope help. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.