Hi, Learning Godot.
I'm following this tutorial that it makes a Minigolf project. My problem is that I try to stop the Ball (Rigidbody) when the LinearVelocity.Length < 0.1, but it doesn't work.
Here is the code (C#)
using Godot;
using System;
public class Ball : RigidBody
{
[Signal]
delegate void Stopped();
public void Shoot(float angle, float power)
{
var force = Vector3.Forward.Rotated(Vector3.Up, angle);
ApplyImpulse(Vector3.Zero, force * power / 5f);
}
public override void _IntegrateForces(PhysicsDirectBodyState state)
{
GD.Print($"LinerVelocity: {state.LinearVelocity}");
GD.Print($"LinerVelocity.Lenght: {state.LinearVelocity.Length()}");
if (state.LinearVelocity.Length() <= 0.1f)
{
GD.Print("--> Emit Signal Stopped");
EmitSignal(nameof(Stopped));
// TODO: for some reason we can't stop the ball
state.LinearVelocity = new Vector3(0, 0, 0);
// state.LinearVelocity *= 0;
}
}
}
I tried also with GDScript and found the same problem
Any idea how to implement this?
Thanks.