Advertisement
rishabbansal21

Learn 3D Games in Python | Ursina Engine | Part-5 Collision Detection

May 6th, 2021
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. from ursina import *
  2.  
  3. speed = 0.05
  4.  
  5. def update():
  6.     global speed
  7.     ball.x += speed
  8.  
  9.     hit_info = ball.intersects()
  10.     if hit_info.hit:
  11.         speed *= -1
  12.         ball.color = color.random_color()
  13.  
  14.         if hit_info.entity in boxes:
  15.             speed *= 1.05
  16.             destroy(hit_info.entity)
  17.  
  18. app = Ursina()
  19.  
  20. ball = Entity(model="sphere", scale=0.5, color=color.yellow, collider="box")
  21. box_1 = Entity(model="cube", scale=(1,2,1), position=(2,0,0), color=color.cyan, texture="white_cube", collider="box")
  22. box_2 = duplicate(box_1, x=-2)
  23. box_3 = duplicate(box_1, x=4)
  24. box_4 = duplicate(box_1, x=-4)
  25. box_5 = duplicate(box_1, x=6)
  26. box_6 = duplicate(box_1, x=-6)
  27.  
  28. boxes = [box_1, box_2, box_3, box_4, box_5, box_6]
  29.  
  30. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement