semih yılmaz
semih yılmaz

Reputation: 129

Player looks like teleporting instead of moving smoothly when camera damping is enabled GODOT

Camera or other nonmoving objects does not look like teleporting when moving the camera with damping. Player does not look like teleporting when camera is stationary. Player does not look like teleporting when camera follows player without damping. But when camera is set to follow player with damping, player looks like teleporting (other nonmoving objects still appear normal).

Code at the camera

func _process(delta):
    #Smooth transition
    var to = character.position + origin
    camPosWoutOffset = smoothTo(camPosWoutOffset, to, smoothness, delta)

    #offset added to smoothed position
    self.global_transform.origin = Vector3(camPosWoutOffset.x + offset.x,
    origin.y + offset.y, camPosWoutOffset.z + offset.z)

func smoothTo(from: Vector3, to: Vector3, smoothness: float, delta: float) -> Vector3:
    var output = Vector3(damp(from.x, to.x, smoothness, delta),
    to.y, damp(from.z, to.z, smoothness, delta))
    return output

func damp(source: float, target: float, smoothing: float, delta: float) -> float:
    return lerp(source, target, 1 - pow(smoothing, delta))

Code at the player

    accel = axis * 150 * delta
    velocity += accel
    velocity = velocity.limit_length(MaxSpeed)
    move_and_slide()

How it looks: https://youtu.be/s1cYYLDoNk8 https://www.youtube.com/watch?v=s1cYYLDoNk8

I have tried lerp, slerp both with and without "delta time" but all had problems.

Upvotes: 0

Views: 94

Answers (1)

semih yılmaz
semih yılmaz

Reputation: 129

should've wrote "_physics_process(delta):" instead of "_process(delta):" fixed it.

Upvotes: 1

Related Questions