Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class pohyb : MonoBehaviour
  5. {
  6. private Rigidbody rb;
  7. public float speed = 10f;
  8. public float jumpForce = 8f;
  9. public float gravity = 30f;
  10. private Vector3 moveDir = Vector3.zero;
  11.  
  12. void Start()
  13. {
  14.  
  15.  
  16. }
  17.  
  18. void Update()
  19. {
  20. CharacterController controller = gameObject.GetComponent<CharacterController>();
  21. if (controller.isGrounded)
  22. {
  23. moveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  24. moveDir = transform.TransformDirection(moveDir);
  25. moveDir *= speed;
  26. if (Input.GetButtonDown("Jump"))
  27. {
  28. moveDir.y = jumpForce;
  29. }
  30. }
  31. moveDir.y -= gravity * Time.deltaTime;
  32. controller.Move(moveDir * Time.deltaTime);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement