godot: KinematicBody2D.get_collision_count() is not working correctly
bugsquadedit: It seems KinematicBody2D.get_collision_count() is not working for some reason. It might be somehow related to the fact there is no KinematicBody2D.is_colliding() method in 3.0 (not sure why?). Uploading reproduction project below, since original one is not compiling:
Issue: KinematicBody2D_collision_count().zip
Tested on 1a92906b681735a5a2acfd98e3d6a4c75a7f6115
edit2: from @novemberist comment it seems it’s not working only when used together with move (and working with move_and_slide)
Operating system or device - Godot version: Windows 7 64bit - Godot 3.0 alpha1
Issue description:
This video shows the bug: https://www.youtube.com/watch?v=hZOAgQEiuYA If i press right arrow key, it suppose to make the sprite move right, at the same speed. but for some reason, the sprite keeps slowing down. The same code is running fine on the stable ( steam ) version of Godot engine.
Steps to reproduce: Make KinematicBody2D, add a Sprite and a CollisionShape2D as childs. add to the KinematicBody2D this code:
extends KinematicBody2D
const GRAVITY = 16.0
const WALK_SPEED = 20
var velocity = Vector2()
func _ready():
set_process(true)
set_fixed_process(true)
pass
func _process(delta):
if (Input.is_action_pressed("ui_left")):
velocity.x = - WALK_SPEED
elif (Input.is_action_pressed("ui_right")):
velocity.x = WALK_SPEED
else:
velocity.x = 0
func _fixed_process(delta):
velocity.y += delta * GRAVITY
var motion = velocity * delta
motion = move(motion)
if (is_colliding()):
var n = get_collision_normal()
motion = n.slide(motion)
velocity = n.slide(velocity)
move(motion)
Save that object. Create new scene, add a new node, and than add this object as his child. To the root node ( the new node of the scene) add StaticBody2D and add it a CollisionShape2D. Than run the scene and press left arrow key or right arrow key and see the sprite slowing down after a while. Link to minimal example project:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (10 by maintainers)
get_collision_count() somehow only reports collisions when using move_and_slide(), but not when using move()