Need help converting C# to GDScript

danjodanjo Posts: 80Member

Hi everyone!

I'm trying to translate this Unity-C#-Script to GDScript
This script implements quake 3 cpm-like movement in Unity, see this video of the original author: link

The basic movement on the ground is working fine but two things cause me some trouble:
1. jumping:
the character just does a minimal jump.. I guess it has to do something with the way that i'm checking if the player is colliding with the floor but i'm not sure
2. the function AirControl:
if I don't move while jumping everything is fine but if do move while jumping playerVelocity.x and playerVelocity.z get very high (or very low depending on direction).
This is what I get in the console while jumping + moving forward (on negative z)

playerVelocity: (-31.217297, 0, -396.653412)
playerVelocity: (-5732674.5, -0.166667, -72840544)
playerVelocity: (-35501225092415464931328, -0.333333, -451085870939387686027264)
ERROR: move: Condition ' p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15 ' is true.
   At: core/math/octree.h:864.
ERROR: _set_transform: Object went too far away (more than 10000000mts from origin).
   At: servers/physics/collision_object_sw.h:90.
ERROR: move: Condition ' p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15 ' is true.
   At: core/math/octree.h:864.
playerVelocity: (-inf, -0.5, -inf)
ERROR: _ensure_valid_root: Octree upper size limit reeached, does the AABB supplied contain NAN?
   At: core/math/octree.h:587.
ERROR: move: Condition ' !common_parent ' is true.
   At: core/math/octree.h:957.
playerVelocity: (-inf, -0.666667, -inf)

I pushed a minimal project to github

If I can do anything to make it easier for you to help me, please tell me :smile:


Tags :


  • danjodanjo Posts: 80Member
    Answer ✓

    Fixed it. Made a stupid mistake:
    I did velocityPlayer.normalized() instead of playerVelocity = playerVelocity.normalized()

    Here's the diff for anyone who cares:

    diff --git a/scripts/ b/scripts/
    index 72603d7..228e7d1 100644
    --- a/scripts/
    +++ b/scripts/
    @@ -176,8 +176,7 @@ func AirControl(wishdir, wishspeed, delta):
            playerVelocity.y = 0
            # Next two lines are equivalent to idTech's VectorNormalize()
            speed = playerVelocity.length()
    -       playerVelocity.normalized()
    +       playerVelocity = playerVelocity.normalized()
            dot =
            k = 32
            k *= airControl * dot * dot * delta
    @@ -188,7 +187,7 @@ func AirControl(wishdir, wishspeed, delta):
                    playerVelocity.y = playerVelocity.y * speed + wishdir.y * k
                    playerVelocity.z = playerVelocity.z * speed + wishdir.z * k
    -               playerVelocity.normalized()
    +               playerVelocity = playerVelocity.normalized()
                    moveDirectionNorm = playerVelocity
            playerVelocity.x *= speed

    still need to make the jump work but I guess it's better to put this in another question

Sign In or Register to comment.