[Resolved] Yet Another "Camera Follow" Thread ;)

Okay, so I’ve seen a lot of threads for simulating a camera following a physics object (such as a character). I successfully have x-axis following set up correctly in addition to y-axis while the object is rooted on an elevator platform. I’m doing this by just moving all objects relative to the player and it works wonderfully.

The main problem I’m having now is following a free-falling physics object. Basically I need to be able to keep a falling object centered have the “falling” motion stop when the object hits a platform. Does anybody have any examples or pointers for doing something like this? Any hints at all would be greatly appreciated!

Thanks! [import]uid: 172008 topic_id: 32848 reply_id: 332848[/import]

I’m not sure I get what you mean with a “falling” motion stop, I think you’ve got the camera-following thing all worked out so I think that isn’t your problem. Are you trying to detect when an object hits the platform then play a specific animation when this happens? If so just search “collision detection” in the site, you’ll find everything you need there :slight_smile: [import]uid: 144908 topic_id: 32848 reply_id: 130590[/import]

I’m not sure I get what you mean with a “falling” motion stop, I think you’ve got the camera-following thing all worked out so I think that isn’t your problem. Are you trying to detect when an object hits the platform then play a specific animation when this happens? If so just search “collision detection” in the site, you’ll find everything you need there :slight_smile: [import]uid: 144908 topic_id: 32848 reply_id: 130590[/import]

No, sorry for the confusion. Maybe my original question was a little nonsensical in its phrasing. :slight_smile:

I totally understand collision detection and physics. I have the camera-following working out for tracking an object on the x-axis and somewhat of the y-axis. My problem is what if an object is falling down to an area that is below currently viewable window, and how can I follow it in that manner? I think I’m pretty close to having it worked out, I just thought I would see if anybody else already had an example of this.

Thanks for responding! [import]uid: 172008 topic_id: 32848 reply_id: 130626[/import]

No, sorry for the confusion. Maybe my original question was a little nonsensical in its phrasing. :slight_smile:

I totally understand collision detection and physics. I have the camera-following working out for tracking an object on the x-axis and somewhat of the y-axis. My problem is what if an object is falling down to an area that is below currently viewable window, and how can I follow it in that manner? I think I’m pretty close to having it worked out, I just thought I would see if anybody else already had an example of this.

Thanks for responding! [import]uid: 172008 topic_id: 32848 reply_id: 130626[/import]

FYI - already worked out a solution. It’s a little convoluted, but if anybody needs an example feel free to reach out to me. [import]uid: 172008 topic_id: 32848 reply_id: 130648[/import]

FYI - already worked out a solution. It’s a little convoluted, but if anybody needs an example feel free to reach out to me. [import]uid: 172008 topic_id: 32848 reply_id: 130648[/import]

I’d love to see an example. thatssopanda (at) gmail.com [import]uid: 14218 topic_id: 32848 reply_id: 131472[/import]

I’d love to see an example. thatssopanda (at) gmail.com [import]uid: 14218 topic_id: 32848 reply_id: 131472[/import]

Sorry Daniel, somehow missed your response. At this exact moment, my code is nowhere near presentable but I can certainly tell you how I was able to accomplish through a means that worked for me.

Like any other movement, I’ve found it easiest to move all objects in relation to the player.

One thing to not about my project is that I want keep my characters y-axis value constant throughout the game. After I first initialize the character, I give it a value for “startY” which equals it’s starting y value.

[lua]player.startY = player.y [/lua]

Then I have a method run every frame called “updateYAxis” that would look something like this:

[lua]–check if player exists
if (player) then
–check if player has fallen
if player.y > player.startY then
–calculate the amount the player has fallen
–in my project I found it easier to round this by using math.floor
–math.floor is optional though, depending on what you’re doing.
yDiff = player.y - player.startY
–assuming you are keeping all of your objects in an array,
–move everything in the array the amount that the player fell
for i = 1, objectArray.numChildren do
objectArray[i].y = y - yDiff
end
end
end[/lua]

Now if you aren’t keeping your player at a static y coordinate you would want to add additional logic to update his “startY” value at the appropriate time.

Feel free to e-mail me with any questions. I’m by no means an expert but this is just one way I found to do this that seems to be what I needed. :slight_smile: tonyjlunt[at]gmail.com [import]uid: 172008 topic_id: 32848 reply_id: 131670[/import]

Sorry Daniel, somehow missed your response. At this exact moment, my code is nowhere near presentable but I can certainly tell you how I was able to accomplish through a means that worked for me.

Like any other movement, I’ve found it easiest to move all objects in relation to the player.

One thing to not about my project is that I want keep my characters y-axis value constant throughout the game. After I first initialize the character, I give it a value for “startY” which equals it’s starting y value.

[lua]player.startY = player.y [/lua]

Then I have a method run every frame called “updateYAxis” that would look something like this:

[lua]–check if player exists
if (player) then
–check if player has fallen
if player.y > player.startY then
–calculate the amount the player has fallen
–in my project I found it easier to round this by using math.floor
–math.floor is optional though, depending on what you’re doing.
yDiff = player.y - player.startY
–assuming you are keeping all of your objects in an array,
–move everything in the array the amount that the player fell
for i = 1, objectArray.numChildren do
objectArray[i].y = y - yDiff
end
end
end[/lua]

Now if you aren’t keeping your player at a static y coordinate you would want to add additional logic to update his “startY” value at the appropriate time.

Feel free to e-mail me with any questions. I’m by no means an expert but this is just one way I found to do this that seems to be what I needed. :slight_smile: tonyjlunt[at]gmail.com [import]uid: 172008 topic_id: 32848 reply_id: 131670[/import]