Advertisement
PetrifiedOnion

Godot stuff 2

Jun 15th, 2024
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends CharacterBody2D
  2.  
  3. var ballIsActive = false
  4. var SPEED = 4000.0
  5.  
  6. var direction
  7.  
  8. # Get the gravity from the project settings to be synced with RigidBody nodes.
  9. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
  10.  
  11.  
  12. func _physics_process(delta):
  13.    
  14.     var collision = move_and_collide(velocity * delta)
  15.    
  16.     if ballIsActive == false:
  17.         direction = (get_global_mouse_position() - self.global_position).normalized()
  18.    
  19.    
  20.     if collision:
  21.         velocity = velocity.bounce(collision.get_normal())
  22.    
  23.        
  24.     if Input.is_action_just_pressed("ui_accept"):
  25.         if ballIsActive:
  26.             pass
  27.         else:
  28.             velocity = SPEED * 5 * delta * direction
  29.             ballIsActive = true
  30.  
  31.  
  32.     move_and_collide(velocity * delta)
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement