|
|
|
|
Reply From: |
p7f |
What is not working? collisions or movement?
So, you mapped “left” and “right” actions to some keys? cause i tried on my machine and it works fine. I used this and moved with the arrows:
extends KinematicBody2D
var velocity = Vector2(250,0)
const SPEED = 550
func _ready():
pass
func getinput():
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
else:
velocity.x = 0
func _physics_process(delta):
getinput()
move_and_collide(velocity * delta)
If you want to change the velocity with the touchscreen buttons, then you should try checking if they are pressed with something like:
if get_node("TouchScreenButtonRight").is_pressed():
velocity.x = SPEED
elif get_node("TouchScreenButtonLeft").is_pressed():
velocity.x = -SPEED
else:
velocity.x = 0
Obviously, replacing for your nodes names in the get_node
function.
About the collisions, for KinematicBody2D to collide, those collision shapes have to be children of other bodies, like StaticBody2D, or RigidBody2D. Bodies collide with bodies, they dont collide with just shapes. Areas dont collide, but detect when a body or other area enter or exit the area.
Sorry, I forgot to tell that the collisions arent working
Criepstar | 2020-07-29 17:21
Collisions with other bodies, right? i see in the tree you showed above, you have some collision shapes and collisions polygons, but for KinematicBody2D to collide, those collisions have to be child of other bodies, like StaticBody2D, or RigidBody2D. Bodies collide with bodies, they dont collide with just shapes. Areas dont collide, but detect when a body or other area enter or exit the area.
Thanks its working now and honestly I feel a little bit stupid, because I looked at a old project and thought that this could’t be the problem. Once again thank you for your help
Criepstar | 2020-07-29 17:39
glad to help! You may select the answer so others see its solved. Ill eddit and add about the collisions.
I selected it, didn’t knew i could do this
Criepstar | 2020-07-29 21:07