Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- public float KecBergerak = 0;
- public float gravity = 6;
- public float kecJalan = 4;
- public float kecLari = 6;
- public float kecLompat = 15;
- private float v_velocity;
- public float jump_Force = 10f;
- Vector3 arahGerak;
- CharacterController controller;
- void Start()
- {
- controller = GetComponent<CharacterController>();
- }
- void Update()
- {
- Move();
- }
- void Move()
- {
- float gerakX = Input.GetAxis("Horizontal");
- float gerakZ = Input.GetAxis("Vertical");
- arahGerak = new Vector3(gerakX, 0, gerakZ);
- if (controller.isGrounded)
- {
- //arahGerak = new Vector3(gerakX, 0, gerakZ);
- if (Input.GetKey(KeyCode.LeftShift) && gerakZ == 1)
- {
- KecBergerak = kecLari;
- }
- else
- {
- KecBergerak = kecJalan;
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- //arahGerak.y += kecLompat;
- v_velocity = jump_Force;
- }
- if (Input.GetKey(KeyCode.LeftControl))
- {
- controller.height = 0.75f;
- }
- else
- {
- controller.height = 2f;
- }
- arahGerak *= KecBergerak;
- }
- v_velocity -= gravity * Time.deltaTime;
- arahGerak.y = v_velocity;
- arahGerak = transform.TransformDirection(arahGerak);
- controller.Move(arahGerak * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement