How do i make the player stay on a moving platform without teleporting to the centre
my current code just says: if player is touching platfrom, player x = platform x
How do i make the player stay on a moving platform without teleporting to the centre
my current code just says: if player is touching platfrom, player x = platform x
this depends on the way you are currently moving the platform
are you using velocity?
or are you incrementing the platform by x | y values?
if your using velocity simply assign the player the same velocity as the platform your currently touching and undo it once the player is no longer touching it
otherwise make the players x | y also increment at the platforms movement incrementation
i want to make to platform moveable with the arrow keys, so this is what i have right now:
if (keyDown(“left”)) {
plt4.x -= pltspeed;
iplt4.x -= pltspeed;
}
if (keyDown(“right”)) {
plt4.x += pltspeed;
iplt4.x += pltspeed;
}
would it be easier to use velocity or is there a simple way with my current code?
(btw thx for responding to so many of my questions)
hmm well if it’s just a single platform there shouldn’t be an issue what you have looks fine but hopefully you are checking that the user isTouching or colliding with the platform to allow the user to use it
if(plt4.collide(plt)) {
var direction = keyDown("right") - keyDown("left"); // produces 1 or -1
plt4 += pltspeed * direction;
iplt4 += pltspeed * direction;
}
this example removes needing multiple if statements and only checks if the player is making contact with the platforms
Thank you for ur responses, i finally fixed the bug!