|
|
|
| View previous topic :: View next topic |
JayCally
Joined: 22 Apr 2009 Posts: 45 Location: RI
|
Posted: Fri Nov 13, 2009 3:34 am Post subject: Best way to stop the camera from at edge of level |
|
|
|
I have a game level that is just a plane with the camera above the player looking down. The player can go to the edge of the level but I don't want the camera seeing past the edge. If you have every played miniGORE for the iPhone, I'm trying to set the camera up like that.
What is the best way of doing this?
The attached photo shows the camera not moving past a certain point and the character not moving past a "box collider".
|
|
| Back to top |
|
|
Raiden
Joined: 08 Feb 2009 Posts: 115 Location: Greenwood, AR
|
Posted: Fri Nov 13, 2009 7:04 am Post subject: |
|
|
|
Just find the minimum and maximum positions on both sides and clamp the transform to keep from going beyond those positions.
| Code: |
var minPosition : float = -10.0; // left border
var maxPosition : float = 10.0; // right border
function Update() {
transform.position.x = Mathf.Clamp(transform.position.x, minPosition, maxPoosition);
} |
Something like that.
-Raiden
_________________
| Quote: | | It Doesn't matter if "we" win or lose. It's how we "make" the game! |
|
|
| Back to top |
|
|
JayCally
Joined: 22 Apr 2009 Posts: 45 Location: RI
|
Posted: Fri Nov 13, 2009 8:59 pm Post subject: |
|
|
|
Thanks for the reply. Is the min/max positions taken from the size of the level? And this script gets added to the camera?
|
|
| Back to top |
|
|
Raiden
Joined: 08 Feb 2009 Posts: 115 Location: Greenwood, AR
|
Posted: Sat Nov 14, 2009 6:04 am Post subject: |
|
|
|
The min and max positions would be the borders of your level, for example in my Breakout clone game, I figured out the borders by moving the paddle as far as I want to go to the left:
You can see in the Transform "x" position I know I'm going to clamp my paddle from moving no further to the left @ -12, which will be the minimum amount in the clamp, then you just move your object all the way to the right you want to go, and that will be the maximum value in the clamp. Just use the positions in the Transform and you will be able to find your limits. Oh, and yes you would use this script on your camera.
-Raiden
_________________
| Quote: | | It Doesn't matter if "we" win or lose. It's how we "make" the game! |
|
|
| Back to top |
|
|
JayCally
Joined: 22 Apr 2009 Posts: 45 Location: RI
|
Posted: Sat Nov 14, 2009 8:02 pm Post subject: |
|
|
|
| Raiden, thanks so much.
|
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|
|
|