daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var myTransform : Transform;
  2. var speed = 0.1;
  3. var onGround;
  4. var Halfsize : double;
  5. function Update () {
  6.     var controller : CharacterController = GetComponent(CharacterController);
  7.  
  8. if(Input.GetKey(KeyCode.D)){
  9.      myTransform.position += myTransform.TransformDirection(Vector3.forward*speed);
  10. }
  11. if(Input.GetKey(KeyCode.A)){
  12.      myTransform.position -= myTransform.TransformDirection(Vector3.forward*speed);
  13. }
  14. if(Input.GetKey(KeyCode.W) && onGround){
  15.      myTransform.position += myTransform.TransformDirection(Vector3.up*speed);
  16. }
  17. }
  18.    //Called every frame that a collider is touching another.
  19. function OnCollisionStay(collision : Collision) {
  20.     //Assume we're not on the ground
  21.     onGround = false;
  22.     //For all the points of contact in the collider
  23.     for (var contact : ContactPoint in collision.contacts) {
  24.         //Is one of the contact points near your feet?
  25.         if(contact.point.y < myTransform.position.y - Halfsize) {
  26.             //If so, then we must be on the ground!
  27.             onGround = true;
  28.         }
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top