wall climbing script
I just started learning coding, and I'm trying to make a wall-climbing script. But I don't know how to make it not move vertically under the "else” section. Here is the piece of code.
using System.Collections; using UnityEngine; private void OnCollisionEnter2D(Collider2D other) { If (other.CompareTag(“Wall”)) { Vector3 playerInput. = new Vector3(0, Input.GetAxisRaw(“Vertical”), 0); } else { Vector3 playerInput. = new Vector3(0, Input.GetAxisRaw(“Vertical”), 0) } }
using System.Collections; using UnityEngine; private void OnCollisionEnter2D(Collider2D other) { If (other.CompareTag(“Wall”)) { Vector3 playerInput. = new Vector3(0, Input.GetAxisRaw(“Vertical”), 0); } else { Vector3 playerInput. = new Vector3(0, Input.GetAxisRaw(“Vertical”), 0) } }
6 Replies
To prevent the player from moving vertically when not in contact with a wall, you can simply set the vertical input to zero in the "else" section of your code.
Ohh
Thank you
No stress. If you need the code snippet it will look like this:
Vector3 playerInput. = new Vector3(0, 0, 0);
Thank you
$close
Use the /close command to mark a forum thread as answered