Moving Platform [SOLVED]


(I'll tell you what I want, what I really really want) #1

Hello again, fellow devs. I have yet another problem. Here’s what a troubled polish boy can’t understand:

(Sry for the quality, again on my phone, having no internet connection is killing me).

What you see here is my poor attempt to move my platform up and down. But it doesn’t really work. Previously I tried creating variable that would hold, let’s say number 5 and move it by that variable’s value, but it wasn’t working either.

I just want it to move it up and down. There’s gotta be an easy way to do that.

Anyone willing to help?


(TaylorAnderson) #2

you might want to change ‘==’ to => or <=. probably due to the increment you’re not going to hit those numbers exactly.


(I'll tell you what I want, what I really really want) #3

Still not working bro. I changed the += and -= to 5 now to get that bad boy running smoothly but it still won’t move.


(Jacob Albano) #4

Don’t know if it’ll make a difference, but make sure to call super.update() at the beginning of your function.


(I'll tell you what I want, what I really really want) #5

I did now :slight_smile: still not working though.

I’m wondering what could cause this code not to work. In my simple mind everything seems to be okay.


(Linck) #6

A very simple way would be like this:

On your update:

this.y += speed * FP.elapsed;

if(this.y > 400){
	speed *= -1;
	this.y = 400;
}
if(this.y < 200){
	speed *= -1;
	this.y = 200;
}

Then you would need to declare a speed variable for your entity class:

private var speed:Number = 20;

(Justin Wolf) #7

Have you tried removing the if statements and just a simple y += 200 * FP.elapsed to see if your Entity is actually updating?


(Jacob Albano) #8

Ah, beat me to it. This is what I was going to say. The platform conditionals well get to a point where none of them are true, so it won’t move at all.


(I'll tell you what I want, what I really really want) #9

It worked! Thank you guys so much! Best community in the whole wide web. Still, my player falls from the platform when it’s going back up, but I’m sure I’ll figure it out.

Thanks again!