Advertisement
lencH

Raycast distance example

Jun 6th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. laser = Besiege.GetBlock("LASER 1")
  2. water_cannon = Besiege.GetBlock("WATER CANNON 1")
  3. water_cannon.SetToggleMode("HOLD TO SHOOT", True)
  4.  
  5. def Update():
  6.     # we use laser position as origin of the raycast and add forward vector for offset to avoid raycasting laser block body
  7.     origin = laser.Position + laser.Forward
  8.     # we use laser forward direction vector as raycast direction
  9.     direction = laser.Forward
  10.  
  11.     try:  # raycasting raises exception if it doesn't hit anything
  12.         hit = Besiege.GetRaycastHit(origin, direction)   # point of the raycast hit
  13.         distance = (hit - origin).magnitude              # calcuate distance from origin to hit position
  14.         water_cannon.SetSliderValue("POWER", distance / 10.0)
  15.         water_cannon.Shoot()
  16.     except:
  17.         pass  # do nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement