Lock Camera on X or Y
by Victor Ferenzi · in Torque X 2D · 03/20/2009 (1:03 pm) · 9 replies
I am trying to figure out how to keep my camera from moving up and down as my player jumps.
This would be simular to Super Mario. As Mario moves to the right the camera is fixed so the Y poistion does not change.
Any help would be appreicated.
Thanks,
This would be simular to Super Mario. As Mario moves to the right the camera is fixed so the Y poistion does not change.
Any help would be appreicated.
Thanks,
#2
08/20/2009 (2:47 pm)
My suggestion would be to create a dummy object, have it snap to the x coordinate of the player per tick, but have it's y be unchanged. Then have the camera follow that object.
#3
That should do it.
John K.
08/20/2009 (2:51 pm)
Do you currently have the camera mounted to the player? I think the easiest way to do this is to not mount the camera to the player. Then create a new component, called CameraFollowComponent (or something) that is added to the player object. Then, within the CameraFollowComponent, request tick processing with a call to AddTickCallback() in the component registration. Also in the registration, get a reference to the camera object using a call to TorqueObjectDatabase. Finally, inside the ProcessTick() method, update the X position of the camera reference equal to the X position of the component's owner, but not the Y position. That should do it.
John K.
#4
i was trying this:
camera.WarpToPosition(new Vector2(_sceneObject.Position.X, camera.Position.Y),0);
but it was jerky?
John if I do the camera component, should I still use WarpToPos?
The camera veiwlimits in TXB seem to work for now as well...
08/20/2009 (3:09 pm)
that was speedy thanks guysi was trying this:
camera.WarpToPosition(new Vector2(_sceneObject.Position.X, camera.Position.Y),0);
but it was jerky?
John if I do the camera component, should I still use WarpToPos?
The camera veiwlimits in TXB seem to work for now as well...
#5
08/20/2009 (3:17 pm)
What's nice about keeping it bound to the player (or dummy object) is the Mountforce option- for that slight lag...
#6
John K.
08/20/2009 (3:17 pm)
Not in this case, Dan. WarpToPosition() is great for moving an object and anything mounted to that object in one single step. But since the camera should not have anything mounted to it, it will be slower that simply setting the camera's new position. Mainly because the WarpToPosition() uses an iterator to recursively call mounted objects. In the grand scheme of things, the performance difference may not be noticeable at all until the scene gets a lot bigger.John K.
#7
08/20/2009 (6:48 pm)
Are you not planning on the camera to ever move on the Y axis? If not, why don't you just set it's world limits to where it cant?
#8
John K.
08/20/2009 (9:44 pm)
That would work, too. But I think you will incur a cost with the collision checking. Again, these are minor costs, so go with any of these options you feel most comfortable with.John K.
#9
I will however work on the suggestion made by John to learn.
08/22/2009 (11:35 am)
Thanks for all the reponses. A short time after I posted this question I discovered a component called CameraManager. I am currently using that in my game. It works well and has some features I would like to use as my game progresses. I will however work on the suggestion made by John to learn.
Torque Owner Dan Pascal