Question by
FlamingoGrande · Nov 12, 2018 at 08:19 PM ·
c#movementraycast
How to stop player from moving forward when they run into a wall?
When my player runs into a wall it keeps him from jumping until I stop pushing the forward button. I was wondering if there was a way to the player from moving forward when he hits a wall. I heard that there was a way to do this with raycasts but I'm pretty new at this whole scripting thing don't know how to implement that into my code.
// Use this for initialization
void Start ()
{
//Makes cursor invisible
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void FixedUpdate ()
{
//Player movement: straffe along x-axis and translate along z-axis
float translation = Input.GetAxis("Vertical") * speed;
float straffe = Input.GetAxis("Horizontal") * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate(straffe, 0, translation);
//Makes cursor visible if you press escape
if (Input.GetKeyDown("escape"))
Cursor.lockState = CursorLockMode.None;
}
This is my movement code
Comment
Your answer
Follow this Question
Related Questions
Jump Using Raycast. 0 Answers
How can I get vector coordinates from a raycast relative to an object? 0 Answers
Raycast Check in GetKey? 0 Answers
help with player movement 0 Answers
How do you change your z axis in a movement script. 1 Answer