Problem with default positions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nick888

Hi guys.

I really face an inconvenient problem:

I have a KinematicBody2D. From the top to bottom of the Kinematicbody2D I have implemented a collisionshape2d(rectangle shape). The moving code of Kinematicbody2D is the following:

func _physics_process(_delta):

motion.y=motion.y+gravity
if Input.is_action_just_pressed(“ui_right”):
motion.x = max_speed
elif Input.is_action_just_pressed(“ui_left”):
motion.x = -max_speed
else:
motion.x=0
motion=move_and_slide(motion)

With the above code the kinematicbody2D does 2 specific moves.Two moves to the left and two moves to the right.

When objects fall from the sky and detect the collisionshape2d of the top of Kinematicbody2D, then the obcects do the following moving:

func _physics_process(_delta):

Heading

rotation +=7*_delta
vel.x=120
vel.y +=gravity
var collision=move_and_collide(vel*_delta)
if collision:
	get_node("Sound").play()
	vel=vel.bounce(collision.normal)
	vel.y=-240

Now.To the right and left sides respectively of Kinematicbody i have implemented two Aread2D.So, if an object touching sideways the kinematicbody2d then the object dissapears (body.queue_free() ). All ok untill now.

The problem is that, when i move the kinematicbody2d and an object touching it at the
sideways then the kinematicbody2D loses the default position because at the same time the falling object touches and the collisionshape2D of the kinematicbody2D

Any suggestions please so as the kinematicbody2d to maintain the default positions?

Thank you.

Use the { } button to format the code.

Code Format Button

Dlean Jeans | 2019-07-03 07:57

Hi guys.

I really face an inconvenient problem:

I have a KinematicBody2D. From the top to bottom of the Kinematicbody2D I have implemented a collisionshape2d(rectangle shape). The moving code of Kinematicbody2D is the following:

func physicsprocess(_delta):
#

motion.y=motion.y+gravity
if Input.isactionjustpressed("uiright"):
motion.x = maxspeed
elif Input.isactionjustpressed("uileft"):
motion.x = -maxspeed
else:
motion.x=0
motion=moveandslide(motion)

With the above code the kinematicbody2D does 2 specific moves.Two moves to the left and two moves to the right.

When objects fall from the sky and detect the collisionshape2d of the top of Kinematicbody2D, then the obcects do the following moving:

func physicsprocess(_delta):
Heading

rotation +=7*_delta
vel.x=120
vel.y +=gravity
var collision=move_and_collide(vel*_delta)
if collision:
    get_node("Sound").play()
    vel=vel.bounce(collision.normal)
    vel.y=-240

Now.To the right and left sides respectively of Kinematicbody i have implemented two Aread2D.So, if an object touching sideways the kinematicbody2d then the object dissapears (body.queue_free() ). All ok untill now.

The problem is that, when i move the kinematicbody2d and an object touching it at the
sideways then the kinematicbody2D loses the default position because at the same time the falling object touches and the collisionshape2D of the kinematicbody2D

Any suggestions please so as the kinematicbody2d to maintain the default positions?

Thank you.

Nick888 | 2019-07-03 08:15

You can edit your post to add format.

Dlean Jeans | 2019-07-03 08:18

Thank you very much.i will check it out.

Nick888 | 2019-07-03 08:25