0 votes

I am making a 3d platformer, there are a lot of animated moving platforms in this game. On my computer the exported version works great, but on different computers when player stands on platform he gets pushed off.

in Engine by (41 points)

Can we see your code for the player?

My code:

extends KinematicBody

export var speed = 20
export(float) var Ladder_speed = 1


const ACCEL_DEFAULT = 7
const ACCEL_AIR = 2
onready var accel = ACCEL_DEFAULT
export var gravity = 40
export var jump = 12
export var Ladder_jump = 20


var cam_accel = 40
var mouse_sense = 0.25
var snap



var direction = Vector3()
var velocity = Vector3()
var gravity_vec = Vector3()
var movement = Vector3()

var Is_on_moving_platform = false


onready var head = $Head
onready var camera = $Head/Camera

onready var Ladder_ray = $Head/ladder_ray
var Is_on_ladder = false
var Can_move_down_on_ladder = false

onready var Timer_label = $Timer
var time = 0


func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

--------------------------------------------------------------------------------------------------------------------------------------------

func _input(event):
    #get mouse input for camera rotation
    if event is InputEventMouseMotion:

    rotate_y(deg2rad(-event.relative.x * mouse_sense))
    head.rotate_x(deg2rad(-event.relative.y * mouse_sense))
    head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))

--------------------------------------------------------------------------------------------------------------------------------------------

func _process(delta):
    #camera physics interpolation to reduce physics jitter on high refresh-rate monitors
    if Engine.get_frames_per_second() > Engine.iterations_per_second:
        camera.set_as_toplevel(true)
        camera.global_transform.origin = camera.global_transform.origin.linear_interpolate(head.global_transform.origin, cam_accel * delta)
        camera.rotation.y = rotation.y
        camera.rotation.x = head.rotation.x
    else:
        camera.set_as_toplevel(false)
        camera.global_transform = head.global_transform

--------------------------------------------------------------------------------------------------------------------------------------------

falling damage code

if is_on_floor() and gravity_vec.length() >= 40 and gravity_vec.length() <= 59:
    PlayerStats.change_health(-20)
    pass

if is_on_floor() and gravity_vec.length() >= 60 and gravity_vec.length() <= 79:
    PlayerStats.change_health(-40)
    pass

--------------------------------------------------------------------------------------------------------------------------------------------

func _physics_process(delta):
    #get keyboard input
    direction = Vector3.ZERO
    var h_rot = global_transform.basis.get_euler().y
    var f_input = Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward")
    var h_input = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
    direction = Vector3(h_input, 0, f_input).rotated(Vector3.UP, h_rot).normalized()

--------------------------------------------------------------------------------------------------------------------------------------------

if is_on_floor():
    snap = -get_floor_normal()
    accel = ACCEL_DEFAULT
    gravity_vec = Vector3.ZERO
else:
    snap = Vector3.DOWN
    accel = ACCEL_AIR
    gravity_vec += Vector3.DOWN * gravity * delta

--------------------------------------------------------------------------------------------------------------------------------------------

if Input.is_action_just_pressed("jump") and is_on_floor():
    snap = Vector3.ZERO
    gravity_vec = Vector3.UP * jump

--------------------------------------------------------------------------------------------------------------------------------------------

if Is_on_ladder == false:
    velocity = velocity.linear_interpolate(direction * speed, accel * delta)
    movement = velocity + gravity_vec

    move_and_slide_with_snap(movement, snap, Vector3.UP)    

--------------------------------------------------------------------------------------------------------------------------------------------

if Is_on_ladder == true and Input.is_action_pressed("move_forward") and Can_move_down_on_ladder == false:
    gravity_vec = Vector3.ZERO
    move_and_collide(Vector3.UP * Ladder_speed)

if Is_on_ladder == true and Can_move_down_on_ladder == true and Input.is_action_pressed("move_forward"):
    gravity_vec = Vector3.ZERO
    move_and_collide(Vector3.DOWN * Ladder_speed)       

if Is_on_ladder == true and Can_move_down_on_ladder == false and Input.is_action_just_pressed("jump"):
    Is_on_ladder = false    
    snap = Vector3.ZERO
    gravity_vec = Vector3.UP * Ladder_jump


if Is_on_ladder == true and Can_move_down_on_ladder == true and Input.is_action_just_pressed("jump"):
    Is_on_ladder = false
    Can_move_down_on_ladder = false     
    snap = Vector3.ZERO
    gravity_vec = Vector3.UP * Ladder_jump

#checks if raycast is looking down at area, that allows moving down 
if Ladder_ray.is_colliding():
    if Ladder_ray.get_collider().is_in_group("Ladder_area") and Can_move_down_on_ladder == false:
        Can_move_down_on_ladder = true

    if !Ladder_ray.get_collider().is_in_group("Ladder_area") and Can_move_down_on_ladder == true:
        Can_move_down_on_ladder = false

--------------------------------------------------------------------------------------------------------------------------------------------

dying()
time_counting(delta)
reset_time(delta)
#print(PlayerStats.health)

--------------------------------------------------------------------------------------------------------------------------------------------

func dying():
    if PlayerStats.health <= 0:
        get_tree().quit()

--------------------------------------------------------------------------------------------------------------------------------------------

counts time

func time_counting(delta):
    time += delta
    var roundtime = float(time)
    Timer_label.text = str(roundtime).pad_decimals(1)

resets the timer

func reset_time(delta):
    if Input.is_action_just_pressed("restart"):
        time = 0
        time_counting(delta)

I am sorry I don't have the time to analyze all that code, but let me just tip You, that the most frequent reason game works different on different machines - is not applying delta in movement calculation

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.