MOBILE OPTIMISED REALISTIC FPS PREFAB FREE
MOBILE OPTIMISED REALISTIC FPS PREFAB CODE
If (surfacePlane.Raycast(ray, out enter)) Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition) Create a ray from the Mouse click position SurfacePlane.SetNormalAndPosition(Vector3.up, transform.position) (transform.position + new Vector3(-offsetVector.y * 2, 0, offsetVector.x * 2)) = Vector3.Lerp(, transform.position + cameraOffset, ltaTime * 7.4f) OffsetVector = cursorPosition - playerPosOnScreen PlayerPosOnScreen = playerCamera.WorldToViewportPoint(transform.position) ĬursorPosition = playerCamera.ScreenToViewportPoint(Input.mousePosition) R.AddForce(new Vector3(0, -gravity * r.mass, 0)) We apply gravity manually for more tuning control R.velocity = new Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z) R.AddForce(velocit圜hange, ForceMode.Velocit圜hange) Velocit圜hange.z = Mathf.Clamp(velocit圜hange.z, -maxVelocit圜hange, maxVelocit圜hange) Velocit圜hange.x = Mathf.Clamp(velocit圜hange.x, -maxVelocit圜hange, maxVelocit圜hange) Vector3 velocit圜hange = (targetVelocity - velocity) Apply a force that attempts to reach our target velocity TargetVelocity = new Vector3(Input.GetAxis("Horizontal") * (cameraDistance >= 0 ? -1 : 1), 0, Input.GetAxis("Vertical") * (cameraDistance >= 0 ? -1 : 1)) TargetVelocity = new Vector3(Input.GetAxis("Vertical") * (cameraDistance >= 0 ? -1 : 1), 0, Input.GetAxis("Horizontal") * (cameraDistance >= 0 ? 1 : -1)) Calculate how fast we should be moving If (cameraDirection = CameraDirection.x)ĬameraOffset = new Vector3(cameraDistance, cameraHeight, 0) Įlse if (cameraDirection = CameraDirection.z)ĬameraOffset = new Vector3(0, cameraHeight, cameraDistance) TargetObject = Instantiate(targetIndicatorPrefab, Vector3.zero, Quaternion.identity) as GameObject Plane that represents imaginary floor that will be used to calculate Aim target position Public CameraDirection cameraDirection = CameraDirection.x Public class SC_TopDownController : MonoBehaviour SC_TopDownController.cs using UnityEngine