0
\$\begingroup\$

I'm trying to make a game where you play basketball as a catapult. Obviously an idea like this leans heavily on the unity physics engine. The cup of the catapult has a bucket on it to keep the ball from falling out. When you hit space, the arm of the catapult spins, which should throw the ball out of the bucket of the catapult. Instead, the ball passes through the cup of the catapult(when it isn't spinning, it acts normally and rolls around the bucket) and then it doesn't fall whatsoever, eve though has gravity is enabled. Here are my physics settings:

The ball

enter image description here

The cup(and also a cup with flipped normals)

enter image description here

The Rim of the bucket

enter image description here

Here's my ball throwing code:

public class BallThrower : MonoBehaviour
{
    private Vector3 axis;
    // Start is called before the first frame update
    void Start()
    {
        axis = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            if (transform.rotation.z > -95.4)
            {
                transform.Rotate(0f, 0f, -5f, Space.Self);

            }
        }
    }
}

What's missing here? Should I make the cup a rigidbody? Let me know if you need more info, Thanks!

\$\endgroup\$
2
  • \$\begingroup\$ You're making the classic mistake of teleporting objects with the Transform component, bypassing the physics system, and expecting the physics engine to come clean up that mess on the next tick. By then, it has very little information about what you wanted to happen - it just sees some objects teleported around, with no velocity or angular momentum sweeping them through that motion - so all it can do is nudge things out of intersection and hope that's what you wanted. If you want physical behaviour, you need to talk to the physics engine. \$\endgroup\$
    – DMGregory
    Commented May 9, 2021 at 13:11
  • \$\begingroup\$ Also, if you want something to function as a "cup" then you definitely don't want it to be convex. A cup is concave by definition. \$\endgroup\$
    – DMGregory
    Commented May 9, 2021 at 23:23

0

Browse other questions tagged .