【发布时间】:2020-08-12 17:34:14
【问题描述】:
我一直在尝试使用我能找到的几乎所有方法(甚至使用可怕的 transform.translate)来让它工作,但我似乎无法让它工作。这只是代码的草稿,如果还有其他方法可以解决,我会更改一些内容。
目前,他几乎没有移动(看起来他不知何故被卡在了地板上。)我对使用刚体移动物体还很陌生,所以我对如何解决这个问题几乎一无所知。
这是我最新破解的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTest : MonoBehaviour
{
public float speed = 10.0f;
public Rigidbody rb;
public Vector3 movement;
// Start is called before the first frame update
void Start()
{
rb.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("w"))
{
movement = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
}
}
void FixedUpdate()
{
moveCharacter(movement);
}
void moveCharacter(Vector3 direction)
{
rb.MovePosition(transform.position + (transform.forward * speed * Time.deltaTime));
}
}
【问题讨论】:
标签: c# unity3d rigid-bodies