Advertisement
PetrifiedOnion

Solved Collision

Jun 20th, 2024
165
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. var collision
  9. var collider
  10. var colliderID
  11.  
  12. # Get the gravity from the project settings to be synced with RigidBody nodes.
  13. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
  14.  
  15.  
  16. func _physics_process(delta):
  17.    
  18.     collision = move_and_collide(velocity * delta)
  19.  
  20.    
  21.     #if ballIsActive == false:
  22.     direction = (get_global_mouse_position() - self.global_position).normalized()
  23.    
  24.     if collision:
  25.         collider = collision.get_collider_id()
  26.         colliderID = instance_from_id(collider)
  27.         velocity = velocity.bounce(collision.get_normal())
  28.         if collider in [25551701228,25669141747,25400706257]:
  29.             pass
  30.         else:
  31.             colliderID.queue_free()
  32.        
  33.     if Input.is_action_just_pressed("ui_accept"):
  34.         #if ballIsActive:
  35.             #pass
  36.         #else:
  37.         velocity = SPEED * 5 * delta * direction
  38.         ballIsActive = true
  39.        
  40.  
  41.     move_and_collide(velocity * delta)
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement