Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class pohyb : MonoBehaviour
- {
- private Rigidbody rb;
- public float speed = 10f;
- public float jumpForce = 8f;
- public float gravity = 30f;
- private Vector3 moveDir = Vector3.zero;
- void Start()
- {
- }
- void Update()
- {
- CharacterController controller = gameObject.GetComponent<CharacterController>();
- if (controller.isGrounded)
- {
- moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
- moveDir = transform.TransformDirection(moveDir);
- moveDir *= speed;
- if (Input.GetButtonDown("Jump"))
- {
- moveDir.y = jumpForce;
- }
- }
- moveDir.y -= gravity * Time.deltaTime;
- controller.Move(moveDir * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement