Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Noob_Maker | |
Old Version | Published before Godot 3 was released. |
I want my Raycasts to not count the player so I typed
raycast.add_exception(self)
but for some weird reason when I added two more raycasts and typed the same thing(with different names of course or else it will be a different problem altogether) I get this error:
Invalid call. Nonexistent function ‘add_exception’ in base ‘Nil’.
And I don’t understand that because 1. that’s a legit thing; raycast.add_exception(self) and 2. this worked previously. What the hell is going on? Do I need to say instead of “self” I say the player object?
Here’s the code for the game at the moment:
extends RigidBody2D
#The variables
var s = 200
var c_s = Vector2(0,0)
var raycast = null
var raycastL= null
var raycastR=null
var jumpforce = 220
var pushoff = 100
#controls
var Right = Input.is_action_pressed("right")
var Left = Input.is_action_pressed("left")
var Jump = Input.is_action_pressed("jump")
#dashing mechanics variables
#Collition thingy so that I don't have to go crazy when the sprite changes and because it will crouch so yeah
#ground check(never thought I'll be using this)
#how to use raycasts(if I ever forget...again):if raycast_1.is_colliding():
#if raycast_1.get_collider().get_name() == "object":
# do_something
#elif raycast_1.get_collider().get_name() == "other_object":
# do_something_else
#raycast_1 = get_node("left_ray")
#raycast_2 = get_node("right_ray")
func is_touching_wall():
if raycastR.is_colliding():
if Input.is_action_pressed ("jump"):
set_linear_velocity(Vector2 (pushoff, get_linear_velocity().y))
func is_on_ground():
if raycast.is_colliding():
return true
else:
return false
func _ready():
CollisionShape = RectangleShape2D.new()
raycast = get_node("RayCast2D")
#raycast = get_node("RayCast2D_left")
#raycast = get_node("RayCast2D_right")
raycast.add_exception(self)
raycastR.add_exception_rid(self)
set_fixed_process(true)
set_gravity_scale(3)
#movement(walking)
func _fixed_process(delta):
Right = Input.is_action_pressed ("right")
Left = Input.is_action_pressed ("left")
Jump = Input.is_action_pressed ("jump")
if Right == true:
set_linear_velocity(Vector2 (s, get_linear_velocity().y))
elif Left == true:
set_linear_velocity(Vector2(-s, get_linear_velocity().y))
else:
set_linear_velocity(Vector2 (0, get_linear_velocity().y))
if is_on_ground():
if Jump:
set_axis_velocity(Vector2(0,-jumpforce))
if is_touching_wall():
if Jump:
set_axis_velocity(Vector2(0,-pushoff))
#dashing
I’m working with a rigid body so don’t give me advice SPECIFICALLY for kinematic bodies
Just a tip apart for the null reference explained on the answers:
If many things need to ignore others, maybe you need to work with different layers and masks instead.
eons | 2017-05-16 16:58