Witam, jak w temacie, potrzebuję poprawki kodu w unity, chodzi o poruszanie się WSADem jak w quake,doomy itd, generalnie first person shooter. Postać porusza się jak w 2d chociaż też nie do końca bo gdzieś ta myszka go lekko prowadzi, no coś jest nie tak :-) Śmiało można się ponabijać, tylko proszę o jakieś instrukcje co jest nie tak. Skrypty przepisane z yt.
Cameracontroller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public float minimumX = -60f;
public float maximumX = 60f;
public float minimumY = -360f;
public float maximumY = 360;
public float sensitivityX = 15f;
public float sensitivityY = 15f;
public Camera cam;
float rotationY = 0f;
float rotationX = 0f;
void Update()
{
rotationY += Input.GetAxis("Mouse X") * sensitivityY;
rotationX += Input.GetAxis("Mouse Y") * sensitivityX;
rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
transform.localEulerAngles = new Vector3(0, rotationY, 0);
cam.transform.localEulerAngles = new Vector3(-rotationX, rotationY, 0);
}
// Start is called before the first frame update
void Start()
{
if (Input.GetKey(KeyCode.Escape))
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Playercontroller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float walkSpeed;
Rigidbody rb;
Vector3 moveDirection;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
float horizontalMovement = Input.GetAxisRaw("Horizontal");
float verticalMovement = Input.GetAxisRaw("Vertical");
moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
}
void FixedUpdate()
{
Move();
}
void Move()
{
Vector3 yVelFix = new Vector3(0, rb.velocity.y, 0);
rb.velocity = moveDirection * walkSpeed * Time.deltaTime;
rb.velocity += yVelFix;
}
// Start is called before the first frame update
void Start()
{
}
}