Can't apply impulse force to Rigidbody

I am trying to apply a random force to a rigidbody with applyImpulse() but it does not seem to work.
I log the vectors and I have tried scaling them as well.
I have tried relaunching unity and the server just in case but still have the same issue.
Any help is appreciated, Thanks!



Untitled_video.mp4

Original Post on Discord

by user 313149111853645827

Maybe this helps for comparison? needle-engine-samples/package/Runtime/_Shared/SampleScripts~/Cannon.ts at main ยท needle-tools/needle-engine-samples ยท GitHub :thinking:

From this sample: Needle Engine Samples

I have updated the code to be similar to the sample and I still seem to have the same issue, it looks like the rigidbody velocity is never updated.


by user 313149111853645827

I just tried with another script which works just fine :thinking:


import { Behaviour, GameObject, Rigidbody, serializable } from "@needle-tools/engine";
import { Vector3 } from "three";

export class PhysicsImpulse extends Behaviour {

    @serializable(Rigidbody)
    rb: Rigidbody | undefined;

    update(): void {

        if (Math.random() < .05 && this.rb) {
            this.rb.applyImpulse(new Vector3(0, Math.random() * 1, 0));
            console.log(this.rb.getVelocity());
        }
    }
}

20221223-164723_Made_with_Needle_-_Google_Chrome.mp4

Added this to an object in the basic physics sample scene

using 2.55.0-pre

Yep, that script works! Impulse seems to only work when called in update. I was trying on call it from collision enter.
I am sure it was in the documentation somewhere but I missed it.
Thanks!

by user 313149111853645827

Ah I see!! No actually I wasnt aware of that. But it makes sense. Will add it to my todos to look into it