Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PugMasterPug |
I have a player, which is a KinematicBody2D
, and I have a moving platform (which is also a KinematicBody2D
) which moves up and down like a sine wave (but only moves upwards and downwards, not to the sides), and I want that when the player steps in the platform, it will stand in top of it (like if it was stuck to the platform). I found some places where this is asked, but it doesn’t seem to work in Godot 3.
If I just try it out, the player stands in the platform, the platform goes down, when it tries to go up it can’t because of the player, and continues then to go down.
I added some code that looked like:
if collider.moving: #moving is boolean variable set to true in this case
speed = collider.speed
But ths has some sort of jitter still.
(btw I move the bodies with move_and_slide(speed)
Can anyone help me please?
Thanks in advance.
What happens if you move the body manually, like described here under the simulated motion section? link
literalcitrus | 2018-02-02 04:08
I don’t get your point, I am already moving the body manually using the move_and_slide (speed)
in the physics_process ()
.
Could you please better explain what you meant?
PugMasterPug | 2018-02-02 04:38
The move_and_slide()
function is part of the API that moves kinematic bodies in a way that allows you to interact with collisions in a friendly way (internally it uses what used to be move()
but with some additional slide calculations). By manually, I mean through modifying or animating the position
property directly. That’s what the “Simulated Movement” in that article is referring to.
literalcitrus | 2018-02-02 04:59
(sorry for answering 10 hours late, my timezone is probably diferent than yours).
If I move the player using position += speed*delta
, the player just falls through everything, so I think you were saying that I should move the platform like that, so when I do, everything works out fine, but when the platform goes down, the player a few pixels on top of the platform, and when the platform rises, the player gets a little bit inside the platform. I am trying to correct that small problem, but I haven’t been able to.
PugMasterPug | 2018-02-02 15:38