This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Trying to get movement correct in 3d isometric view

GeffreyGeffrey Posts: 37Member

I am following this tutorial on 2.5d perspective:

The author mentions and demonstrates that the movement is not in sync when the orthogonal camera is in 45 degrees.

When I press the up arrow I want to move 1/2 speed in the x axis and half speed in the z axis. I'm having difficulty fighting an elegant way to achieve this.

It works somewhat if in the velocity calculation section of the code in the video I do:

    if direction_ground.x != 0:
        velocity = Vector3(
            direction_ground.x * speed/2 + direction_ground.y * speed/2,
            velocity_y,
            direction_ground.y * speed/2 + direction_ground.x * speed/2)
    elif direction_ground.y != 0:
        velocity = Vector3(
            direction_ground.x * speed/2 - direction_ground.y * speed/2,
            velocity_y,
            direction_ground.y * speed/2 - direction_ground.x * speed/2)

The above makes sideways movement work correctly. Diagonal unhandled still

But, I'd prefer to not use this inelegant system with if's.

Comments

  • Ace_DragonAce_Dragon Posts: 323Member

    He did the isometric perspective using the 3D engine with a orphographic camera. If you did the same thing, you should be able to just have the character move along the X and Z axis and it will look correct in the game.

  • GeffreyGeffrey Posts: 37Member
    edited July 2019

    The above code moves the character half along the x axis and half along the z axis when pressing down/up/left/right.

    I'm just wondering if there is a more elegant, less processor intensive way of doing it. I feel like doing ifs every physics step is a bad idea. There any way to make it make the character see the world as rotated so that it sees y-axis as half x and half z?

  • GeffreyGeffrey Posts: 37Member
    edited July 2019

    Here is the full code with mutliple ifs, now with diagonal movement working as. The movement does work how I want it to work, but I feel like there must be a better way without using so many ifs'

        if (direction_ground.x > 0 and direction_ground.y > 0) or (direction_ground.x < 0 and direction_ground.y < 0):
            velocity = Vector3(
                direction_ground.x *speed/2 - direction_ground.y * speed/2,
                velocity_y,
                direction_ground.y *speed/2 + direction_ground.x * speed/2)
        elif (direction_ground.x > 0 and direction_ground.y < 0) or (direction_ground.x < 0 and direction_ground.y > 0):
            velocity = Vector3(
                direction_ground.x *speed/2 - direction_ground.y * speed/2,
                velocity_y,
                -direction_ground.y *speed/2 - direction_ground.x * speed/2)
        else:
            if direction_ground.x != 0:
                velocity = Vector3(
                    direction_ground.x * speed/2 + direction_ground.y * speed/2,
                    velocity_y,
                    direction_ground.y * speed/2 + direction_ground.x * speed/2)
            elif direction_ground.y != 0:
                velocity = Vector3(
                    direction_ground.x * speed/2 - direction_ground.y * speed/2,
                    velocity_y,
                    direction_ground.y * speed/2 - direction_ground.x * speed/2)
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.