Dougkusanagi

Lerp Camera GdScript with Increase X Pos

Jul 24th, 2021 (edited)
515
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Camera2D
  2.  
  3. export (NodePath) var TargetNodepath = null
  4. export (float) var lerpspeed = 0.05
  5. export (float) var increasePosX = 3
  6.  
  7. var target_node
  8. var playerDirection
  9.  
  10. func checkPlayerDirection():
  11.     # Defined in player when he press left is defined to -1, when he press right is defined to 1
  12.     playerDirection = target_node.get("directionX")
  13.    
  14.     if(playerDirection == -1):
  15.         self.position.x -= increasePosX
  16.     else:
  17.         self.position.x += increasePosX
  18.        
  19.     print(playerDirection);
  20.  
  21.  
  22. func _ready():
  23.     #assign the player in editor
  24.     target_node = get_node(TargetNodepath)
  25.  
  26. func _process(delta):
  27.     checkPlayerDirection();
  28.    
  29.     self.position = lerp(self.position, target_node.position, lerpspeed)
  30.  
RAW Paste Data