Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- public class UnityMover : MonoBehaviour
- {
- public float speed = 6.0F;
- public float jumpSpeed = 8.0F;
- public float gravity = 20.0F;
- public Rigidbody rb;
- public float groundCheckRadius;
- public Transform groundCheck;
- public LayerMask whatIsGround;
- private bool Grounded;
- private Vector3 moveDirection = Vector3.zero;
- void Update() {
- CharacterController controller = GetComponent<CharacterController>();
- if (controller.isGrounded || !Grounded)
- {
- moveDirection = new Vector3 (Input.GetAxis("Horizontal"), velocity.y, 0);
- moveDirection = transform.TransformDirection(moveDirection);
- moveDirection *= speed;
- }
- if (Input.GetKeyDown(KeyCode.Space) && Grounded)
- {
- moveDirection.y = jumpSpeed;
- }
- moveDirection.y -= gravity * Time.deltaTime;
- controller.Move(moveDirection * Time.deltaTime);
- }
- void FixedUpdate()
- {
- Grounded = Physics.OverlapSphere (groundCheck.position, groundCheckRadius, whatIsGround).Length > 0;
- /*
- if ((Mathf.Abs (input.x) > float.Epsilon || Mathf.Abs (input.y) > float.Epsilon) && (advancedSettings.airControl || m_IsGrounded)) {
- // always move along the camera forward as it is the direction that it being aimed at
- desiredMove = Vector3.ProjectOnPlane (desiredMove, m_GroundContactNormal).normalized;
- desiredMove.x = desiredMove.x * movementSettings.CurrentTargetSpeed;
- desiredMove.y = desiredMove.y * movementSettings.CurrentTargetSpeed;
- if (m_RigidBody.velocity.sqrMagnitude <
- (movementSettings.CurrentTargetSpeed * movementSettings.CurrentTargetSpeed)) {
- rb.AddForce (desiredMove * SlopeMultiplier (), ForceMode.Impulse);
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement