0 votes

Hello,
I am currently working on the wall run mechanic in my fps game. I am doing this with Raycasts at the left and right of the character, but it won't work. Here is my code:

onready var RaycastRight = $RayCastRight
onready var head = $Head
var wall_run_head_angle = 20

    func _physics_process(delta):
     if(RaycastRight.is_colliding()):
      var collider = RaycastRight.get_collider()
      if(collider.is_in_group("Obstacles")):
       head.rotation_degrees.z = lerp(head.rotation_degrees.z, wall_run_head_angle, 0.1)
      else:
       head.rotation_degrees.z = lerp(head.rotation_degrees.z, 0, 0.1)
Godot version 3.3.3.stable
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Rather than checking consistently if the raycast has a collision you might want to move your code to a signal that emits when a collision happens.

P.S GDScript is case sensitive so know that obstacles, Obstacles, oBstacles are not the same thing

by (4,480 points)
edited by

Thanks for your answere! Ive now fixed it and it works pretty good.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.