Hi everyone,
I am using Lime to create a map. I got an object moving up and down by doing this:
1 2 3 4 5 6 7 8 9 10 11 | function elevatorMove() if elevator then function moveDown() transition.to( elevator, { time=3000, x=(elevator.x), y=(elevator.y + 175), transition = easing.linear, onComplete = moveUp } ) end function moveUp() transition.to( elevator, { time=6000, x=(elevator.x), y=(elevator.y - 175), transition = easing.linear, onComplete = moveDown } ) end moveUp() end end |
The problem is I can't make this object static so when the player hit the object he will move with the platform up and down.
How can I do this or I might ask what am i doing wrong?
b-bond
I figured it out I have some of the properties saved in external json files and my mistake was trying to make it static calling that file.
instead what i have done is this
1 | physics.addBody(elevator, "static", { density = object.density, friction = object.friction, bounce = object.bounce }) |
now it works.
Thans for the patience and the reply peach pellen
B-bond
Maybe you or someone else can answer this question. why are moving objects standing still when hitting the static elevator?
is some kind of force applied to the element hitting the elevator by default?
b-bond
My guess is they're hitting part of the elevator's body and can't move further.
If it's static and has a square body that others walk into they can't "enter" the elevator.
If this is the case you'd want to make a custom body shape, perhaps like an "L" so the player could walk in and out.
Does this sound like your situation? (I'm trying to picture what you are going for so could be way off, please feel free to correct me.)
Peach :)
Not quite what I am aiming for. It is basically a part of the earth moving up and down (old school platform).
But when I try to detect collision it dosen't work. Collision on all other elements work, so I am quite blank on why this is not working 0.o
can it be because I am using transitions to move the elevator?
b-bond
Ah I see; http://developer.anscamobile.com/reference/index/bodybodytype
The dynamic object would be listening for the collision in this scenario.
Take a read :)
Peach
I read the articles a couple of times,
with all other objects I check for collision with the player, the ground for instance (player should be dynamic). It seems to be the elevator only that dosen't check for collision. The only difference is that the elevator has a transition.to on it.
So the player is the one listening for the collision with the elevator but it doesn't trigger, is that right? (Just trying to picture all this.)
I think you pictured it right, the gravity still beep up when I place either a barrel or the player on the elevator :)
OK, are you still having the issue? Player collides with elevator but nothing happens?
I'd be tempted to use a transition on the elevator if it is static.
Is that an option?
Peach :)
I will just paste a bit more code here, as it might help ;)
This is the elevator movement
1 2 3 4 5 6 7 8 9 10 11 | function elevatorMove() if elevator then function moveDown() transition.to( elevator, { time=3000, x=(elevator.x), y=(elevator.y + 175), transition = easing.linear, onComplete = moveUp } ) end function moveUp() transition.to( elevator, { time=6000, x=(elevator.x), y=(elevator.y - 175), transition = easing.linear, onComplete = moveDown } ) end moveUp() end end |
This is the collision (it dosent work)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function onPlayerCollision(event) if event.phase == "began" then if event.other.IsElevator then jumper = true print "le elevator" end end if event.phase == "ended" then if event.other.IsElevator then print "This is not le elevator" jumper = false end end end |
here is the elevator body
1 | physics.addBody(elevator, "static", { density = object.density, friction = object.friction, bounce = object.bounce }) |
and here is the player body
1 | physics.addBody(player, "dynamic", { density = object.density, friction = object.friction, bounce = object.bounce }) |
Hope this helps :)
Thank you in advance Peach or anybody else :)
b-bond
Oh and the IsElevator is set in my json file
1 2 3 4 5 6 7 | { "IsElevator":"", "friction":0, "isSensor":"", "sheet":"elevator.png", "sheetData":"elevator" } |
Have you set any other bodies up this way? What happens in began phase if you do print (event.other.isElevator) ?
Hey there - why can't you make it static, sorry?