C
C#3mo ago
BroDeee

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) } }
6 Replies
SparkyCracked
SparkyCracked3mo ago
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.
BroDeee
BroDeee3mo ago
Ohh Thank you
SparkyCracked
SparkyCracked3mo ago
No stress. If you need the code snippet it will look like this: Vector3 playerInput. = new Vector3(0, 0, 0);
BroDeee
BroDeee3mo ago
Thank you
SparkyCracked
SparkyCracked3mo ago
$close
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered