简体   繁体   English

在Unity 2d中添加速度后没有反弹

[英]No Bounce after adding velocity In Unity 2d

First of all I'm new to Unity and Game programming. 首先,我是Unity和Game编程的新手。 I'm trying to add a cricket bowling like animation. 我正在尝试添加板球保龄球,例如动画。 But when the ball touches the ground It doesn't bounce at all and it shows an weird rolling animation. 但是,当球触地时,它根本不会反弹,并且显示出奇怪的滚动动画。

Here is the GIF, 这是GIF,

没有反弹

So I just added the velocity in code, 所以我只是在代码中添加了速度,

public class Ball : MonoBehaviour {


    public float EndPointX ;
    public float EndPointY ;
    bool ForceAdded = true;
    private Rigidbody2D rigidBody;

    void Start () {
        rigidBody = GetComponent<Rigidbody2D> ();

    }

    void Update () {

        rigidBody.velocity = new Vector3(EndPointX, EndPointY, 0)*2;

    }
}

My Bounce 2d material file, 我的Bounce 2d材质文件,

2D材质

Ball Properties, 球属性

球

It bounces perfectly without any velocity. 它弹跳完美,没有任何速度。 I mean when it falls in a straight angle. 我的意思是当它成直角时。

Thanx For The Help!! 感谢帮助!!

Since Update() runs every frame, you are continuously setting the velocity, and immediately overwriting the bounce materials attempts to change its direction of movement. 由于Update()每帧都运行一次,因此您将连续设置速度,并立即覆盖反弹材质,以尝试更改其移动方向。 If you move the velocity to your Start() method, the velocity will only be set once and the bounciness will be able to influence your object properly. 如果将速度移动到Start()方法,则速度将仅设置一次,并且反弹度将能够正确影响对象。

void Start () {
    rigidBody = GetComponent<Rigidbody2D> ();
    rigidBody.velocity = new Vector3(EndPointX, EndPointY, 0)*2;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM