Petrax
Picopat
- Katılım
- 11 Kasım 2023
- Mesajlar
- 113
- Çözümler
- 2
Daha fazla
- Cinsiyet
- Erkek
C#:
using UnityEngine;
using AFPC;
public class Controller : MonoBehaviour {
public Overview overview;
public float moveSpeed = 5f;
public float jumpForce = 5f;
public float gravity = -9.81f;
public Transform groundCheck;
public LayerMask groundMask;
CharacterController controller;
Vector3 velocity;
bool isGrounded;
private void Start () {
controller = GetComponent<CharacterController>();
QualitySettings.vSyncCount = 0;
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
ReadInput();
overview.Looking();
overview.Aiming();
overview.Shaking();
isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * moveSpeed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpForce * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
private void FixedUpdate () {
}
private void LateUpdate () {
overview.Follow (transform.position);
}
private void ReadInput () {
overview.lookingInputValues.x = Input.GetAxis("Mouse X");
overview.lookingInputValues.y = Input.GetAxis("Mouse Y");
overview.aimingInputValue = Input.GetMouseButton(1);
}
}
Bu kodda istediğimi eğer kamera ile sağa doğru bakıyorsam karakterimde sağa doğru dönsün ve ileri gitme tuşuna basınca baktığım yöne doğru gitsin ancak ben sağa doğru baksam bile ileri basınca karakterin önü neresiyse oraya gidiyor.
Son düzenleyen: Moderatör: