2nd – How one can make redirected participant motion reply to similar key?

2nd – How one can make redirected participant motion reply to similar key?

[ad_1]

I’ve a 2nd sport (Godot 4) with completely different rooms with portals to go between them, and a few portals redirect the route of the participant whereas nonetheless holding the identical key. I’ve that working up to now, however once I launch the important thing, it retains shifting within the redirected route. How can I ensure that the participant stops when it is purported to?

Motion:

if Enter.is_action_just_pressed("left"):
    velocity.x = -1
    $Sprite2D.flip_h = false
elif Enter.is_action_just_pressed("proper"):
    velocity.x = 1
    $Sprite2D.flip_h = true
if Enter.is_action_just_released("left"):
    velocity.x = max(velocity.x,0)
if Enter.is_action_just_released("proper"):
    velocity.x = min(velocity.x,0)

if Enter.is_action_just_pressed("up"):
    velocity.y = -1
elif Enter.is_action_just_pressed("down"):
    velocity.y = 1
if Enter.is_action_just_released("up"):
    velocity.y = max(velocity.y,0)
if Enter.is_action_just_released("down"):
    velocity.y = min(velocity.y,0)

Warp between rooms:

func warp(real_dir,dir): # ULDR
    var odd = dir % 2 == 1
    
    var vpos = place
    var off = -2*MARGIN
    var offw = SIZE - 2*MARGIN
    
    var diff = participant.place - (place + Vector2(SIZE/2,SIZE/2))
    participant.place = diff.rotated((real_dir - dir) * PI/2) + place + Vector2(SIZE/2,SIZE/2)
    
    if dir >= 2:
        off = SIZE + 2*MARGIN
        offw = 2*MARGIN
    
    if odd:
        vpos = Vector2(vpos.y,vpos.x)
        participant.place = Vector2(participant.place.y,participant.place.x)
    
    if warps[dir] == "":
        participant.place.y = vpos.y + off
    else:
        var level_pos = locate_level(warps[dir])
        if odd:
            level_pos = Vector2(level_pos.y,level_pos.x)
        participant.place.x += level_pos.x - vpos.x
        participant.place.y = level_pos.y + offw
    
    if odd:
        participant.place = Vector2(participant.place.y,participant.place.x)
    
    participant.velocity = participant.velocity.rotated((real_dir - dir) * PI/2)
    
    player_inside = not warps[dir] == title

Player going right Player going up in another room

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply