我使用Rigidbody2D速度在C#中为角色运动写了一个脚本。然而,有时当我试图移动时,我的角色移动然后突然冻结并且不会前进。只是向后。我检查了碰撞者他们是所有相等和抢购。我甚至试过AddForce,但它仍然冻结。
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 () {
}
}
答案 0 :(得分:0)
你的角色是否从对撞机走到另一个? 如果是这种情况,请检查碰撞者之间的交叉点是否有回角。