#How to make the spear "stuck" when colliding with the ground?

4 messages · Page 1 of 1 (latest)

vast glade
#

So, basic projectile: RigidBody2d, has a sprite and collision shape. Also has an area2d (for collisions with ground) with it's own shape (both made unique). There is also a collision boolean, to detect collision and stop it.

The spear gets instantiated, is given an impulse of Vector2. The rotation of the spear is controlled by atan2(y,x), to give it a smooth rotation .

However, when the spear collides with the ground, it is given a full stop. All velocities set to zero. Collision boollean is set to false, so the spear is suppesed to stop. Yet, I think there happens one last tick of forces update, screwing up atan2. THEN all process stops, spear gets frozen at this wierd angle

I tried to sus out the values of velocities, but it didn't bear any fruit.

func _integrate_forces(state):
    if(collided):
        var velo = state.linear_velocity
        if velo.y >2  or velo.x > 16: //been toying with this values. Some do work in only specific instances
            var angle = atan2(velo.y, velo.x)
            self.rotation = angle
            print("Y ")
            print(velo.y)
            print("X ")
            print(velo.x)
    else:
        pass


func _on_body_entered(body):
    print("AAAAAAAAAAA") //for debugging
    print(linear_velocity.x)  //this, and the latter print show that a tik of update doo happen
    collided=false
    linear_velocity= Vector2.ZERO
    print(linear_velocity.x) // this, and the former print show that a tik of update doo happen
    angular_velocity=0
    gravity_scale =0
    pass
soft basin
#

I am on mobile as of writing this, so I can't really test any logic.

Maybe try setting up an array used for the collided. Mostly everything from a rigid body should use _integrate_forces, which you have done. So in the _on_body_enter, clear out the list and insert the position and rotation information. Then when collided becomes true use that list to update the position and rotation and freeze the rigid body.

sonic jay
#

you also may want to just freeze the rigidbody once its stuck