我在C#写了一个脚本使用Rigidbody2D velocity.However人物移动,有时当我尝试移动,我的性格然后移动突然冻结,不会去forward.Only backwards.I检查对撞机他们都是平等和snapped.I尝试甚至AddForce,但它仍然冻结。团结Rigidbody2D速度突然冻结
using UnityEngine;
using System.Collections;
public class CharacterController2D : MonoBehaviour {
[SerializeField]
float speed = 5;
[SerializeField]
float jumpForce = 500;
[SerializeField]
LayerMask whatisground;
[SerializeField]
bool isGrounded = false;
Transform groundCheck;
private Rigidbody2D rb2d;
// Use this for initialization
void Start() {
rb2d = gameObject.GetComponent<Rigidbody2D>();
groundCheck = gameObject.transform.GetChild (0);
}
void FixedUpdate(){
float hor = Input.GetAxis ("Horizontal");
rb2d.AddForce (new Vector2 (hor * speed,0));
//rb2d.velocity = new Vector2(hor*speed,rb2d.velocity.y);
isGrounded = Physics2D.OverlapCircle (groundCheck.position, 0.15F);
}
// Update is called once per frame
void Update() {
}
}
你试过指定forcemode? 'rigidbody2D.AddForce(新Vector2(HOR *速度,0),ForceMode2D.Impulse);' – Shakra
没有,但我不认为这真的很重要。 –