Hate to be
constantly asking questions, but presumably this will help people out in the future, right? Right you guys? :dry:
I have my player character animating in my top-down game. As the player moves around, I'd like the camera to follow them. However, if I call
orxCamera_SetParent(camera, player)
...I only get a blank screen. Otherwise, the player and background tiles render just fine without this call.
Does this call not do what I expect? Is there another way to have the camera follow the player around? Thanks.
Comments
And yes, I'm sure it'll help other users, at least those who'll search the forum.
Here my guess is that this call does what it's supposed to do. Your issue probably being a matter of culling in the render plugin.
When you do orxCamera_SetParent(camera, player), now the position of the camera is expressed in the player object's local space. So if you haven't specified any, (0, 0, 0) will be used, which means the camera will have the exact same 3D position as your player.
So, in a more general way, if your camera Z is 0, it has the same Z as the player, which means the player will be culled out (remember that culling has an inclusive far but an exclusive near).
Have you tried setting your camera position at (0, 0, -0.1) (provided your near frustum is < 0.1 and your far frustum is >= 0.1)?
Please also remember that your player scale, if any, will affect the camera own scale & position.
This means that if your player as a scale of (2, 2, 0), the camera's position will be multiplied by 2 on X & Y axes, its zoom will also be affected (being reciprocal to the scale) and might not produce the results you were expecting.
What is worse is that here the player Z scale is 0, which means all the camera Z frustum will get reduced to a single point, which in turn means that every displayable object will be culled out before rendering.
In Mushroom Stew I actually attach the camera to a dummy camera object so that I can then use all the orxOBJECT_* functions on it, including the use of orxFXs and physics.
This dummy camera object can in turn be set as a child of another object, such as your player character.
Hope this helps!
This way you can have a loose camera following the player, using an averager for example.
PS: A good link about different interpolation curves which might turn helpful for that: http://sol.gfxile.net/interpolation/
Setting the camera's position to -0.75 fixes things. It's sort of a cheap hack, but it works.