Seems wrong to just leave this thread dirty like this.
I don’t see the OP doing cursor locks but it’s bound to go there eventually.
Just go for the CharacterControllerPro scripts and hit the ground running.
But for something much simpler, give this a sniff.
using FlaxEngine;
namespace Game
{
// Actor Parenting for this use case
//
// Actor (capsule mesh) (added script here)
// |
// |__ Character Controller (adjusted to default capsule size)
// |
// |__ Camera (position offset back/up {0, 120, -90} from parent origin)
//
// note: I also like to position my origins at the bottom
// which you would normally get from imported character models
//
public class Rotator : Script
{
public Camera cam;
public Vector2 sensitivity = new Vector2(1.0f, 0.4f);
private float _rotX;
private Vector3 _offset = new Vector3(0, 75, 0); // start at Actor head height
public override void OnEnable()
{
Screen.CursorLock = CursorLockMode.Locked; // put us somewhere more appropriate
Screen.CursorVisible = false; //
}
public override void OnUpdate()
{
_rotX += Input.GetAxis("Mouse X") * sensitivity.X; // Input.MousePositionDelta returns zero in locked cursor state
_offset.Y -= Input.GetAxis("Mouse Y") * sensitivity.Y; // negate for reverse look
_offset.Y = Mathf.Clamp(_offset.Y, -75, 200);
Actor.RotateAround(Actor.Position, Transform.Up, _rotX);
//Actor.RotateAround(Actor.Position, Transform.Up, Input.MousePosition.X); // avoid some arbitrary starting rotation
//cam.RotateAround(Actor.Position, Transform.Right, Input.MousePosition.Y); // sure, if you want to get your freak on :)
//cam.RotateAround(Actor.Position, Transform.Right, Input.MousePositionDelta.Y*sensitivity); // still kinda lame
cam.LookAt(Actor.Position + _offset);
// now get inventive with the over the shoulder action on your own
}
public override void OnDisable()
{
Screen.CursorLock = CursorLockMode.None; // these guys go too
Screen.CursorVisible = true; //
}
}
}
references:
I made a third-person movement tutorial!
Free and Open Source Character Controller Pro for Flax Engine!
similar assumptions:
Transform.RotateAround() how to implement it on Flax Engine