Simple 2D Raycast: Nonexistent function 'get_space' in base 'KinematicBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AveryRe
:warning: Old Version Published before Godot 3 was released.

So I’ve been using the exact 2D code from here: http://docs.godotengine.org/en/stable/tutorials/ray-casting.html on a KinematicBody to cast a ray:

func _fixed_process(delta):
self.look_at(global.PLAYER_POS);
var space_state = get_world().get_direct_space_state();
var result = space_state.intersect_ray(get_global_pos(), global.PLAYER_POS, [ self ] );

But it returns:

 Nonexistent function 'get_space' in base 'KinematicBody2D

Any idea what might be causing this behaviour?

Thanks!
Avery

:bust_in_silhouette: Reply From: avencherus

You want to use get_world_2D() for things that are 2D. The one being used in that example is for 3D.

Thanks! This worked. Just a side note for anyone who stumbles on this, get_world_2D() will fail, but get_world_2d() works perfectly.

AveryRe | 2017-02-11 01:09