deltaluca

Untitled

Apr 22nd, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. player presses space;and you have the current direction to throw the rope.
  2.  
  3. set up ray: new Ray(player.position, direction, start_distance);
  4.  
  5. each-frame after pressing space {
  6.  
  7. ray.position = player.position;
  8. var result = space.rayCast(ray);
  9.  
  10. if(result!=null) {
  11. //yay rope hit something
  12. create rope joint with player position, and ray.at(result.distance)
  13. }else {
  14. //still not hit anything
  15. ray.maxDistance += distance_increment;
  16. }
  17. }
  18.  
  19.  
  20. ------------------------------------------ SAME AS ABOVE BUT WITH GRAPHICS ----------------
  21.  
  22. player presses space;and you have the current direction to throw the rope.
  23.  
  24. set up ray: new Ray(player.position, direction, start_distance);
  25.  
  26. each-frame after pressing space {
  27.  
  28. ray.position = player.position;
  29. var result = space.rayCast(ray);
  30.  
  31. if(result!=null) {
  32. //yay rope hit something
  33. create rope joint with player position, and ray.at(result.distance)
  34. start rendering rope as normal based on rope anchor points.
  35. }else {
  36. //still not hit anything
  37. ray.maxDistance += distance_increment;
  38. render rope from player.position up to ray.at(ray.maxDistance)
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment