Moving on a ledge based on camera direction
I added a mechanic to my player so that he can hang from a ledge and shimmy along the side of it. I am able to make it work so that if you hold left the character will go left along the ledge and if you hold right the character will go right along the ledge. This is my code so far:
moveHorizontal = Input.GetAxisRaw("Horizontal");
var desiredVelocity = transform.right * moveHorizontal * ledgeSpeed;
rb.AddForce(desiredVelocity, ForceMode.VelocityChange);
How can I change this so that it will work relative to camera direction. For example, if the camera is facing backwards, holding right will make the character move right relative to the camera, but it is actually moving to the left along the ledge. Also if the camera is looking at the character from the side, I want to be able to press up or down and have the character move forward or backward relative to the camera, but in actuality it will be moving left / right along the ledge.
I can't seem to figure out how to do this. Every attempt I've made moves the character relative to the camera, but not along the ledge. Instead of sticking to the ledge the character will move away from it or move toward it based on the camera direction.
Your answer
Follow this Question
Related Questions
Need help with joystick camera and rotation movement. 0 Answers
No smooth motion, Camera stutters 1 Answer
Camera moving OnTriggerEnter 2 Answers
Trying to connect camera movement with player AND mouse 0 Answers
Swipe camera rotation controller (HELP) 0 Answers