Can't make Rigidbody.AddForce do anything

Hi guys. I’m trying to make objects jitter and fall in a sort of random pattern. To that end, i’m trying to make them jump randomly with an impulse force every 0.1-0.3 seconds

unfortunately it’s just not doing anything, the objects fall in a completely vertical line.

I’m using this function for the pushing:

    void Jump()
    {
        //Here we do some stuff to calculate and apply a jump force
        Vector3 force = Random.onUnitSphere * (jumpForce * Random.value);
        Debug.Log("Applying force " + force);
        //gameObject.GetComponent<Rigidbody>().AddForce(force, ForceMode.Impulse);
        body.AddForce(force, ForceMode.Impulse);
   
        //Now we calculate the time until the next jump
        secsToJump = (maxJumpInterval - minJumpInterval)*Random.value;
    }

i’ve put a debug in there to check that it’s calculating the force numbers correctly, here’s an output with push force set to a crazy high value which should be sending them into the far distance

so it’s definitely running, definitely calculating numbers properly. What’s the issue?

Physical properties are my next thing to check. Here’s one of the objects in question, screenshot taken from runtime while it’s falling

I see nothing here that would prevent an object being pushed around. low mass, not kinematic, no constraints, no drag, etc.

I did tweak the collision filter slightly, here’s my physics menu

the objects are on the nonsolid layer, i want them to collide with the environment but not each other. Ticking that box and allowing them to collide doesn’t fix the issue though

All of that aside, i also want these objects to be triggers instead of solid colliders. I started them out that way but made them solid in an attempt to fix this, no effect. either trigger or solid, they don’t go anywhere but slowly down

I’m stumped, please provide leads and guesses

I’m not even gonna ask what you’re trying to do with your jumping, but I find just doing

public Rigidbody myRigid;
public float speed;
public float jumpForce;

void FixedUpdate(){
if(Input.GetKey(KeyCode.W)){
myRigid.velocity = new Vector3(0,jumpForce,speed);
}
}

Works perfectly fine for me.

You can try a forcemode that ignores the mass e.g. ForceMode.velocityChange

You have assigned the Rigidbody in the IDE check that they link to the right LightningProbe’s you could have them all linked up to one that has flown out of your scene while the others fall without a jitter?

It’s best to get and assign rigidbody references in the Start or Awake functions and have them as private variables.

As you can see from a commented out line in the first snippet, that already ocurred to me, i made sure that’s not happening, and i tested with that line to be sure, no difference. the forces are definitely being applied to the correct body

oki ive fixed it i believe, i screwed up of course

in the couroutine that i’m triggering jumps from, i forgot to stick an infinite loop in there, so it just applied a force once. getting a better result now. problem solves i guess <3

1 Like

Tip: Don’t use GetComoponent in your game loop when you can avoid it. In this case, you should have a Start() or Awake() function setup the rigidbody variable you use in Update functions.

1 Like