0 votes

Hello, i am trying to build a simple space shooter game, but i am stumbling in some aspects of the physics engine.

Actually i have a spaceship and a asteroid. I made the ship kinematic and the asteroid a RigidBody2D, because i wanted it to rotate when they collided. But when i move the spaceship using:

    move(velocity * delta)

The asteroid wont move at all. But when i move the ship using:

    set_pos(get_pos() + velocity * delta)

The asteroid behaves like expected and moves/rotates.

I am having a hard time trying to understand that. If someone could help me i would be really thankful.

in Engine by (16 points)

3 Answers

0 votes

Just my guess, but I think the kinematicbody doesn't actually do anything within the physics engine by itself. You have access to the physics engine methods to make it move, but if you want it to push other bodies, you have to code it. You have to manage everything, including going through all colliding objects and give them an impulse. Quite a lot of work for less performance if you want to do the same thing as the rigidbody. Are you sure you don't want to use the rigidbody?

by (703 points)

Humm, you are right, i'll rethink my implementation, and do some tests with a rigidbody.

0 votes

If I understand you correctly your problem is that the kinematic body you move doesn't push the asteroid aside when using the move()-method?
When you read the documentation for that method you will find that move doesn't move a kinematic body all the way to the destination but only as far as possible without colliding into anything. That means that if you use the move-command the kinematic body will stop moving before it hits anything and therefore can't push anything aside.

by (1,124 points)

humm, ok i read that, and thought that could be it, but i was intrigued that the "setPos" method moved the asteroid.

0 votes

Godot newbie here (so I don't know if this is a bad idea or if there's a better way), but this worked for me:

func _fixed_process(delta):
    # ...calculate desired velocity, e.g. due to keypresses
    # ...then move the character

    motion = move(motion)
    if (is_colliding()):
        # If bumping into a rigid body, push it!
        var collider = get_collider()
        if (collider extends RigidBody2D):
            collider.apply_impulse(motion, collider.get_pos() - get_collision_pos())

    # etc

At the moment I'm using this to make a user-controller KinematicBody2D push around a circular RigidBody2D (platformer).

by (19 points)
edited by

A non-programatically solution is to add another KinematicBody as child of the one using move with similar (or the same) shape as the parent, and different layer/masks, of course, make the rigid ignore the KB that uses "move" (mask).

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 Frequently asked questions and 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 [email protected] with your username.