Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myTransform : Transform;
- var speed = 0.1;
- var onGround;
- var Halfsize : double;
- function Update () {
- var controller : CharacterController = GetComponent(CharacterController);
- if(Input.GetKey(KeyCode.D)){
- myTransform.position += myTransform.TransformDirection(Vector3.forward*speed);
- }
- if(Input.GetKey(KeyCode.A)){
- myTransform.position -= myTransform.TransformDirection(Vector3.forward*speed);
- }
- if(Input.GetKey(KeyCode.W) && onGround){
- myTransform.position += myTransform.TransformDirection(Vector3.up*speed);
- }
- }
- //Called every frame that a collider is touching another.
- function OnCollisionStay(collision : Collision) {
- //Assume we're not on the ground
- onGround = false;
- //For all the points of contact in the collider
- for (var contact : ContactPoint in collision.contacts) {
- //Is one of the contact points near your feet?
- if(contact.point.y < myTransform.position.y - Halfsize) {
- //If so, then we must be on the ground!
- onGround = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment