1
\$\begingroup\$

This is how my game looks so far:

enter image description here

I feel the physics are off. The ball is just instantly slowing down instead of flying across that floor.

You can see the drag is turned down so I don't know why the physics look so bad?

Any ideas? The scale is like 3x smaller than a 1x1 cube.

In case it's a script problem, here is the code on the physics I've done to move the player (note: the GIF does not contain any player input at all):

    using UnityEngine;
using System.Collections;

public class PhysicsBall : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    public float maxStamina; // from the editor
    public float staminaReconveryRate; // from the editor
    public float staminaDrainRate; // from the editor
    public float joystickDeadband; // from the editor
    private float currentStamina;
    public float nothing;

    void Start ()
    {
        rb = GetComponent<Rigidbody> ();
        currentStamina = maxStamina;
    }

    // Update is called once per frame
    void FixedUpdate () {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        // Make sure the player actually ask to move; this is done to avoid spending stamina when 
        // not expecting it
        bool hasHorizontal = false;
        bool hasVertical = false;
        if ( Mathf.Abs( moveHorizontal) > joystickDeadband )
            hasHorizontal = true;
        else
            moveHorizontal = 0.0f;

        if ( Mathf.Abs( moveVertical ) > joystickDeadband )
            hasVertical = true;
        else
            moveVertical = 0.0f;

        // player requests to move
        if ( hasHorizontal || hasVertical )
        {
            // and has stamina
            if (currentStamina > 0.0)
            {
                // lets move him and consume stamina
                Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertical);

                rb.AddForce (movement * speed);

                currentStamina -= Time.deltaTime * 70;
            }
        }
        else
        {
            // the player does not request to move, so we restore the stamina. 
            moveHorizontal = 0.0f;
            moveVertical = 0.0f;
        }

    }

    void Update () {
        Debug.Log (currentStamina);
    }


}

/* public class PhysicsBall : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start ()
    {
        rb = GetComponent<Rigidbody> ();
    }

    // Update is called once per frame
    void FixedUpdate () {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertical);

        rb.AddForce (movement * speed);
    }
}
*/

EDIT: I discovered something weird in the project but it's a different question so I made a new question: Both are scale 1, one is a lot smaller

But it's very likely to relate to this problem as the larger ball works fine.

\$\endgroup\$
5
  • \$\begingroup\$ Definitely not correct. I don't use Unity, but i could imagine erratic frame times passed to the physics calculation might produce something like this. Eg. if you (erratically) pass a fixed frame delta time and FPS suddenly drops towards the end of the movement (sorry for not knowing if you separately pass time in Unity). Anyway, something with time, might be a place to look into.. \$\endgroup\$
    – Stormwind
    Commented Aug 21, 2016 at 18:49
  • 1
    \$\begingroup\$ What is the drag value of the ground plane? \$\endgroup\$
    – Tashus
    Commented Aug 21, 2016 at 19:21
  • \$\begingroup\$ The (cube) doesn't have a rigidbody. But I tried that with a mass of 5000 (so it wouldn't fly everywhere) and no change with 0 drag. \$\endgroup\$
    – Paze
    Commented Aug 21, 2016 at 19:32
  • \$\begingroup\$ How is the physics material of the ball, the ground and the pipe configured? \$\endgroup\$
    – Philipp
    Commented Aug 21, 2016 at 20:13
  • \$\begingroup\$ I tried with all sorts of settings but if I want the ball to actually roll, I need some friction, or else it just scoots off with super unrealistic motion (but it goes more realistically "fast"). I think on the GIF, there is no material. Just default. \$\endgroup\$
    – Paze
    Commented Aug 21, 2016 at 20:27

3 Answers 3

1
\$\begingroup\$

My guess is the friction between the ball and the slide isn't high enough so that it's not actually gaining much of a roll. Looks like you have a no friction material applied to the sphere collider? Friction is actually your friend.

When applying physics to a ball, I would use torque on the ball, combined with higher friction, and not translation force. Movement without friction is very unrealistic for a ball and it'll be damned difficult to try to simulate different surfaces like ice, rubber, etc. Looks like you're trying to circumvent the physics system instead of working inside of it, which can cause odd behaviors like you're seeing.

Edit: Can't comment yet so adding this here. If you ever do want immovable objects to work in the physics engine with masses/etc, check the option for IsKinematic. This will allow the mass to influence some of the physics behaviors but force applied to it will not cause any motion. Great for things like programmatically moved platforms. Definitely check out some of the physics tutorials on unity's site.

\$\endgroup\$
1
  • \$\begingroup\$ I tried adding dynamic and static friction to the physics material on the ball. It's even slower then. \$\endgroup\$
    – Paze
    Commented Aug 22, 2016 at 8:19
0
\$\begingroup\$

You mentioned the scale is 3x smaller than a 1x1x1 cube, which doesn't sound that unreasonable, but just to rule this out, maybe try making the scale more representative of the situation you're trying to model. For example, if the ball is supposed to be a soccer ball, and the standard sphere mesh has a 1-unit (in Unity, "1 unit" is "1 meter") diameter, you should scale it down to 0.22 of its original size (soccer ball circumference is 70 cm, so diameter is ~22 cm, which is .22 m).

From http://docs.unity3d.com/Manual/class-Rigidbody.html

The size of the your GameObject’s mesh is much more important than the mass of the Rigidbody. If you find that your Rigidbody is not behaving exactly how you expect - it moves slowly, floats, or doesn’t collide correctly - consider adjusting the scale of your mesh asset. Unity’s default unit scale is 1 unit = 1 meter, so the scale of your imported mesh is maintained, and applied to physics calculations. For example, a crumbling skyscraper is going to fall apart very differently than a tower made of toy blocks, so objects of different sizes should be modeled to accurate scale.

Good luck.

\$\endgroup\$
0
\$\begingroup\$

Problem found:

The ball was a child object to a parent which I had not noticed was scaled severely down. Turns out my ball was very, very tiny and that makes the engine treat it like that.

I scaled the parent up to 1 and the ball behaves normally.

\$\endgroup\$
1
  • \$\begingroup\$ mark this answer correct \$\endgroup\$
    – Andreas
    Commented Aug 22, 2016 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .