Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Movement.js, based on RigidbodyFPSWalker
- var speed : float;
- var jumpHeight : float;
- var maxVelocityChange : float;
- var grounded : boolean;
- var cam : Transform;
- function Start () {
- }
- function FixedUpdate () {
- if (grounded) {
- var targetVelocity = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
- targetVelocity = cam.transform.TransformDirection(targetVelocity);
- targetVelocity *= speed;
- var v = rigidbody.velocity;
- var velocityChange = (targetVelocity-v);
- velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
- velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
- velocityChange.y = 0;
- rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
- }
- if(Input.GetButtonDown("Jump") && grounded){
- rigidbody.AddForce(transform.up*jumpHeight);
- }
- grounded=false;
- }
- function OnCollisionStay(collision : Collision) {
- if (collision.transform.tag != "Not Ground"){
- grounded=true;
- }
- }
- __________________________________________________________________________________________________
- __________________________________________________________________________________________________
- //MouseLook.js
- var sensibility : float;
- function Start () {
- }
- function Update () {
- transform.Rotate(Vector3(0,Input.GetAxis("Mouse X")*sensibility,0), Space.World);
- transform.Rotate(Vector3(-Input.GetAxis("Mouse Y")*sensibility,0,0));
- }
Advertisement
RAW Paste Data
Copied
Advertisement