This should work. Why not?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TheExtraNerdyFox

Heres my code:

func _physics_process(_delta):
   apply_gravity()
   # L and R movement
   var input = Vector2.ZERO
   input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")

# Slide
  if input.x == 0:
	apply_friction()
	top.animation = "Idle"
	feet.animation = "Idle"
else:
	apply_acceleration(input.x)
	  if input.x > 0:
		top.animation = "Run"
		feet.animation = "Run"
		feet.flip_h = false
		top.flip_h = false
		AWAY_FROM_WALL = -250
		wallCast.cast_to = 11
	  elif input.x < 0:
		top.animation = "Run"
		feet.animation = "Run"
		feet.flip_h = true
		top.flip_h = true
		AWAY_FROM_WALL = 250
		wallCast.cast_to = -11

Its the wallCast.cast_to = [int] that doesn’t work. Why?

ITS SO FRUSTRATING!!!

TheExtraNerdyFox | 2022-12-31 15:05

:bust_in_silhouette: Reply From: idbrii

If wallCast is a Raycast node? cast_to is a Vector3.

Try:

wallCast.cast_to = Vector3.DOWN * 11

Usually, the reason it doesn’t work is explained by the error message. Usually you’ll get helpful results if you search for the error message.

Would I use Vector2? The game is 2D. Error: Invalid set index 'cast_to' (on base: 'Raycast2D') with value of type Vector3

TheExtraNerdyFox | 2022-12-31 15:02

Yeah, Vector2. You can check the raycast2d documentation (the DOC icon in Godot will open it quickly for you) and it will tell you what it wants. I think hovering cast_to in the editor should also show you its type.

idbrii | 2022-12-31 17:19