Help with ApplyImpulse on 3D

Godot Version

3.5

Question

I am newb to GameDev, I am currently playing around with Godot 3D.

So, I want to make a simple rolling dice for starter. I am using ApplyImpulse to change its linear position. I enclosed it with 4 walls as barriers, but there are times when the Dice goes through the barriers, and I don’t have a clear idea why…I suspect because the force is too big…but what is “too big”???

Here is my code:

using Godot;
using System;

public class Dice : RigidBody
{
    private bool impulseApplied = false;

    public override void _PhysicsProcess(float delta)
    {
        if (Input.IsActionJustPressed("ui_accept") && !impulseApplied)
        {
            Sleeping = false;
            GD.Print("Applying impulse", LinearVelocity, LinearVelocity.Length(), Transform.origin);
            ApplyImpulse(Vector3.Zero, new Vector3(2, 0, 0));
            impulseApplied = true;
        } else if (impulseApplied) {
            impulseApplied = false;
        }
    }

    public override void _IntegrateForces(PhysicsDirectBodyState state)
    {
        if (impulseApplied) {
            GD.Print(state.LinearVelocity, state.LinearVelocity.Length(), state.Transform.origin);
        }
    }
}

I also noticed that the LinearVelocity is not 0, even though my dice is not moving…I don’t know why either

using Godot;
using System;

public class Dice : RigidBody
{
    private bool impulseApplied = false;

    public override void _PhysicsProcess(float delta)
    {
        if (Input.IsActionJustPressed("ui_accept") && !impulseApplied)
        {
            Sleeping = false;
            GD.Print("Applying impulse", LinearVelocity, LinearVelocity.Length(), Transform.origin);
            ApplyImpulse(Vector3.Zero, new Vector3(2, 0, 0));
            impulseApplied = true;
        } else if ((impulseApplied)) {
            impulseApplied = false;
        }
    }

    public override void _IntegrateForces(PhysicsDirectBodyState state)
    {
        // if (impulseApplied) {
        //     GD.Print(state.LinearVelocity, state.LinearVelocity.Length(), state.Transform.origin);
        // }
        GD.Print(state.LinearVelocity, state.LinearVelocity.Length(), state.Transform.origin);
    }
}

Is it actually still moving? But the linearvelocity is too small that it seems to not moving??

Here is my env setup:







Thank you in advance!!

If the dice are to-scale (very small) that can cause problems for the physics precision. You could scale up the size of the dice to 1 unit and just increase gravity to match it and see if that helps. Making the collision shapes thicker might also help.

1 Like

Try to use jolt physics of Godot, you can download it

Yea, this works, I make the dice 2x bigger…but is it possible without “guessing” the size? How do I know if size is the issue? :thinking:

Interesting, I will tinker it too!

1 Like

It works better with jolt, guess I will use this for now lol
thanks !!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.