【发布时间】:2016-04-20 13:51:34
【问题描述】:
所以我尝试在 Unity 5 中制作游戏。这是一个2D 游戏,我希望我的角色自动前进。但我的问题是,由于我使用 Rigidbody2D.AddForce,它会不断增加每一帧的力,我不希望这样。我希望我的 速度 保持在 5.0f,而不是或多或少。有没有办法设置限制或保持恒定速度?
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public Rigidbody2D player;
public bool grounded = false;
private bool hasJumped = false;
public float movementspeed = 5.0f;
public float jumpforce = 450.0f;
// Use this for initialization
void Start () {
player = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
player.AddForce(transform.right * movementspeed);
// (JumpScript)
}
void FixedUpdate(){
// (JumpScript)
}
}
【问题讨论】:
-
答案是(1)你必须使用实数单位,单位1米是“真的”1米,单位一公斤真的是一公斤(2)不可能成为物理游戏程序员除非您 .................... 是物理学方面的专家。考虑一下。想象一下你对某人说“我要编程物理”。他们当然会认为你是物理学、机械工程等方面的专家。
-
@Icevx1 你可能想看一些统一的教程here
标签: c# vector unity3d 2d unity5