0 votes

Here's the code for spawning object which is rigidbody node:

func spawn_asteroid():
    var spawn_position: Vector3 = get_spawn_position()

    var asteroid_instance = asteroid_scene.instance()
    asteroid_instance.transform.origin = spawn_position
    spawned_asteroids.append(asteroid_instance)

    # Push towards player
    var direction_to_player: Vector3 = player.transform.origin - spawn_position
    asteroid_instance.add_force(direction_to_player * asteroid_speed, spawn_position)

    add_child(asteroid_instance)

There's no add_torque or any additional codes to handle rotation, however when object spawned, it spins like spinning top.

First I thought that it caused if two rigidbody objects are intersected and push each other and cause rotation, but it wasn't.

Have no idea why they are spinning. Is there a something that I missed? Unlike Unity, there's no way to stop their rotation. Using Godot 3.1.1.

in Engine by (132 points)

1 Answer

+2 votes
Best answer

The RigidBody will spin if you add the force to another position than (0,0,0).
add_force takes two parameters.
force: is the force vector which b.t.w. is "rotated" in global space/coordinate system.
position: is the position where the force is applied. This position is "rotated" in the global coordinate system but relative to the RigidObject.

https://docs.godotengine.org/en/3.1/classes/class_rigidbody.html#class-rigidbody-method-add-force

In your case, you should be able to just pass Vector3() as second parameter.

by (3,203 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories