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!!