1
\$\begingroup\$

when the player uses the teleportation skill, he is instantly teleported X distance in the direction of movement so front, back, left and right depending in which direction the player wants to go.

the first problem with this system was falling through the terrain, to stop it I added a ray below the feet of the player that points downward, if it checks that there is terrain, the player will teleport on that terrain.

also added another ray on the player's head, this one points towards the sky... if it checks that there is land above the player's head, it will be teleported with his feet landed on the above terrain.

so no more falling endlesly through the emptiness by teleporting inside the terrain...

but one problem I have never manage to fix.... teleporting inside walls or teleporting inside enemies or inside other players.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ If the raycast is working for not getting stuck up or down, why not use another raycast in the direction of teleport and stop the teleport short by the distance of hit detection? \$\endgroup\$
    – Zibelas
    Jun 24, 2023 at 7:31
  • \$\begingroup\$ @Zibelas first thing i tried, literally..... didn't work \$\endgroup\$
    – Cei
    Jun 24, 2023 at 10:21
  • 1
    \$\begingroup\$ It is working exactly the same way. If you say it didn't work, you should include the code you used and any information of errors. \$\endgroup\$
    – Zibelas
    Jun 24, 2023 at 12:26
  • \$\begingroup\$ In addition to the above about including code & errors, describe how it didn't work. As a step toward Zibelas' raycast. instead of stopping short, I would 1st use it as a hard check: allow the full distance teleport if there's no intersections/collisions at all. If that works, then deal with the case of stopping short making sure you take into account the bounding volume of the player - stopping at the point of intersection is probably still too close (though it's hard to know without seeing your code). \$\endgroup\$
    – Pikalek
    Jun 24, 2023 at 17:18
  • \$\begingroup\$ It will include as well a different solution if you are allowed to go through walls and if that is the case, you have as well game design problems to consider (is the player allowed on the other side of the closed boss door/ progress without key item/ etc). Since you wrote players can teleport up on a platform, consider the impact through objects carefully \$\endgroup\$
    – Zibelas
    Jun 24, 2023 at 21:30

1 Answer 1

0
\$\begingroup\$

Fixed it deleted all the rays, I hate rays anyways, for anyone wanting to use it, all you have to do is decide the teleport_distance by asigning it a number and then add a keybind for "blink", then you can just copy and paste this in your func _physics_process(delta):

    if Input.is_action_just_pressed("blink"):
    var forward_direction = -global_transform.basis.z
    var teleport_vector = forward_direction.normalized() * -teleport_distance
    var teleport_position = translation + teleport_vector
    var collision = move_and_collide(teleport_vector)
    if collision:
        teleport_position = collision.position
    translation = teleport_position

keep in mind that this version is adjusted to teleport your player where the camera is pointing not where the player is facing, if you use a different directional system just use your direction variable instead of "forward_direction" also change -teleport_distance by deleting the minus like this

    if Input.is_action_just_pressed("blink"):
    var teleport_vector = direction.normalized() * teleport_distance
    var teleport_position = translation + teleport_vector
    var collision = move_and_collide(teleport_vector)
    if collision:
        teleport_position = collision.position
    translation = teleport_position

The first method is perfect for games with strafing or first person games, the second method is perfect for games like Zelda, Tera, Monster hunter... where movement is complely free and more natural.

ps: if you copy and paste this, adjust the indents/spaces/tabs.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .