Jamope
November 18, 2024, 5:03pm
1
Hello!
How can I make the player able to move sideways while colliding in front? (Like pressing W, colliding, but if you press A or D you can move to the left/right). If I collide with a wall straight forward and keep pressing W, I cannot move sideaways while pressing A or D, and I want the player to be able to.
This is my code for player movement.
private void movePlayer()
{
moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
Vector3 moveForce = moveDirection.normalized * moveSpeed;
rb.AddForce(new Vector3(moveForce.x, 0, moveForce.z), ForceMode.VelocityChange);
}
Sounds like perhaps friction is too high. Use a PhysicMaterial to make those collisions slippery.
If you’re just writing yet another player controller, you may wish to start from some working examples otherwise you’ll be reinventing all the wheels.
Here’s the go-to prototype CharacterController-based FP controller I always use to start:
[BasicFPCC - A basic first person character controller]
Gist Link
After some interest in an old post here , I spent the weekend frankensteining snippets of code to make a single script FPCC that could be used like the FPCC from Unity 4~5, including the crouch and run from Aldo, and I also added farcry sliding. There is a Menu Item function to easily create and configure a new FPCC object. Otherwise very easy to set up, it only requires a layer to exclude itself from sphere/raycasts…
It has run, walk, jump, slide, crouch… it’s crazy-nutty!!