Why does the velocity drop so low?

When playing my game i noticed some interesting changes in velocity ( 1m/s = makes it almost unplayable ). Keep in mind i’m on Video 59 just before the challenge. So i did some digging and found the GUI.Box feature and included it on screen to watch the speed of the ball as it travels. I’m sure we will address this later in the course. Figured i would share either way.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;


public class Velocity : MonoBehaviour
{
    private float speed;
    private float gravity;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        speed = GetComponent<Rigidbody2D>().velocity.magnitude;
       gravity = GetComponent<Rigidbody2D>().gravityScale;
    }

    private void OnGUI()
    {
        GUI.Box(new Rect(10, 10, 100, 60), "Ball Velocity");

        GUI.Label(new Rect(20, 40, 80, 20), speed + "m/s");

        GUI.Box(new Rect(10, 90, 100, 60), "Gravity");

        GUI.Label(new Rect(20, 120, 80, 20), gravity + "m/s");
    }
}

2 Likes

Your velocity drops really low? I have no idea what you mean…

SlowBall

I dig your UI box to show the speed though. I totally stole that.

Might be friction on the material.

Privacy & Terms