Advertisement
Guest User

Ludum Dare 26 antecipated scripts

a guest
Apr 26th, 2013
13,321
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Movement.js, based on RigidbodyFPSWalker
  2.  
  3. var speed : float;
  4. var jumpHeight : float;
  5. var maxVelocityChange : float;
  6. var grounded : boolean;
  7. var cam : Transform;
  8. function Start () {
  9.  
  10. }
  11.  
  12. function FixedUpdate () {
  13. if (grounded) {
  14. var targetVelocity = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  15. targetVelocity = cam.transform.TransformDirection(targetVelocity);
  16. targetVelocity *= speed;
  17. var v = rigidbody.velocity;
  18. var velocityChange = (targetVelocity-v);
  19. velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
  20. velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
  21. velocityChange.y = 0;
  22.  
  23. rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
  24. }
  25. if(Input.GetButtonDown("Jump") && grounded){
  26. rigidbody.AddForce(transform.up*jumpHeight);
  27. }
  28. grounded=false;
  29. }
  30.  
  31. function OnCollisionStay(collision : Collision) {
  32. if (collision.transform.tag != "Not Ground"){
  33. grounded=true;
  34. }
  35. }
  36.  
  37. __________________________________________________________________________________________________
  38. __________________________________________________________________________________________________
  39.  
  40. //MouseLook.js
  41.  
  42. var sensibility : float;
  43. function Start () {
  44.  
  45. }
  46.  
  47. function Update () {
  48. transform.Rotate(Vector3(0,Input.GetAxis("Mouse X")*sensibility,0), Space.World);
  49. transform.Rotate(Vector3(-Input.GetAxis("Mouse Y")*sensibility,0,0));
  50.  
  51. }
Advertisement
RAW Paste Data Copied
Advertisement