本文介绍了Unity Pong游戏球物理变慢问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的乒乓球比赛中,球应该反弹并且永远不会变慢.但是,随着时间的推移,球在稳步减速.我将放置球对象和脚本的图像. 这是左边的球属性

In my game for pong, the ball is supposed to bounce and never become slower. However, the ball is steadily slowing down over time. I will put an image of the ball object and the scripts. Here is the ball properties on the left

这是球剧本 使用UnityEngine;使用System.Collections;

Here is the ball script using UnityEngine;using System.Collections;

公共类球:MonoBehaviour{ 公共浮球速度= 3000;

public class Ball : MonoBehaviour { public float ballVelocity = 3000;

Rigidbody rb;
bool isPlay;
int randInt;

void Awake()
{
    rb = GetComponent<Rigidbody>();
    randInt = Random.Range(1,3);
}

void Update()
{
    if (Input.GetMouseButton(0) && isPlay == false)
    {
        transform.parent = null;
        isPlay = true;
        rb.isKinematic = false;
        if (randInt == 1)
        {
            rb.AddForce(new Vector3(ballVelocity, ballVelocity, 0));
        }
        if (randInt == 2)
        {
            rb.AddForce(new Vector3(-ballVelocity, -ballVelocity, 0));
        }
    }
}

}

这是弹跳物理图像

由于我不知道为什么它不起作用,所以这是我的物理项目设置

and since I have no idea why it won't work, here is my physics project settings

我被困住了并且是团结的新手,所以任何帮助都很棒!如果您需要更多信息,请发表评论!

I have been stuck and am new to unity so any help would be awesome! If you need any more info, comment!

推荐答案

转到您的资产文件夹,然后创建一个 PhysicalMaterial ,并将摩擦"(静态和动态)均设置为0,弹性"设置为0.

Go to you assets folder and create a PhysicMaterial and set both Frictions to (Static and Dynamic) to 0 and Bounciness to 0.

这篇关于Unity Pong游戏球物理变慢问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:29