C
C#12mo ago
BroDeee12

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

Did you find this page helpful?