According to the documentation:
- void set_trigger ( bool enable )
Set whether this shape is a trigger. A trigger shape detects
collisions, but is otherwise unaffected by physics (i.e. will not
block movement of colliding objects).
but it doesn't detects collisions at all. A bug?
I want to stop the body when it hits first time the floor but it doesn't collide at all because it is set as trigger.
Any help is welcome.
extends KinematicBody2D
const GRAVITY = 200.0
var velocity = Vector2()
var gravity
var first_time=true
func _ready():
set_fixed_process(true)
gravity=GRAVITY
get_node("shape").set_trigger(true)
func _fixed_process(delta):
var force = Vector2(0, gravity)
velocity += force*delta
var motion = velocity*delta
motion = move(motion)
if(is_colliding()):
print("colliding")
var n=get_collision_normal()
motion=n.slide(motion)
velocity=n.slide(velocity)
move(motion)
if first_time:
gravity=0
velocity=Vector2(0,0)
print("first_time")
first_time=false