0 votes

I'd like to rotate a kinematic body around world origin 0,0,0, the body is at 0,0,20.

The rotation direction and radius can be changed by user input, so pressing left/right rotates in said direction, up/down grows/shrinks the offset from world origin.

The code below does the trick and interacts with rigid bodies, however it feels somewhat of a hack to pass an "empty" Vector to moveandslide and how would I alter the applied forces on collision with rigid bodies?

Perhaps there's a better way of doing this?

Thanks in advance.

extends KinematicBody

var parent

func _ready():
    parent = get_parent()

func _physics_process(delta):
    var angle = 0

    # Rotation
    if Input.is_action_pressed("ui_left"):
        angle = -delta

    if Input.is_action_pressed("ui_right"):
        angle = delta

    var q = Quat(Vector3(0, 1, 0), angle) * (get_global_transform().origin - parent.get_global_transform().origin) + parent.get_global_transform().origin
    global_transform.origin = q

    # Movement  
    if Input.is_action_pressed("ui_up"):
        global_transform.origin += -get_global_transform().basis.z.normalized() * 0.2

    if Input.is_action_pressed("ui_down"):
        global_transform.origin += get_global_transform().basis.z.normalized() * 0.2

    move_and_slide(Vector3(), Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
    look_at(parent.get_transform().origin, Vector3(0,1,0))

    for i in get_slide_count():
        var collision = get_slide_collision(i)
        if collision.collider.is_class("RigidBody"):
in Engine by (12 points)

Please log in or register to answer this question.

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.