How to clamp camera?
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
How to clamp camera?
Just wondering what methods there are to make a camera that follows a player to stop following the player at a certain place (like next to a wall)? I use camerax but the methods should work for all if you have any clues...
Re: How to clamp camera?
use coordinates of player to check that?
like regular collisions checks, but for camera?
if player inside some zone, then camera should stop following, and when player leaves it, then continue?
like regular collisions checks, but for camera?
if player inside some zone, then camera should stop following, and when player leaves it, then continue?
Re: How to clamp camera?
Gunroar:Cannon() wrote: ↑Sun Oct 03, 2021 12:11 am Just wondering what methods there are to make a camera that follows a player to stop following the player at a certain place (like next to a wall)? I use camerax but the methods should work for all if you have any clues...
Code: Select all
if camera_following then
-- do following
else
-- do not following
end
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: How to clamp camera?
So like collision detection? Would I have to do anything with the scale value? Any resources for how to clamp are also welcome.
Re: How to clamp camera?
you need is X and Y of something that should be followed with camera (for example, player)Would I have to do anything with the scale value?
game window width and height (if your game window can be resized) or game's render width and height if, for example, your game uses option to change resolution of game which will be scaled to
and, maybe, scale value (if you have one)
with X and Y of player and with resolution\window size divined by in-game scale value (if have one) you can determine where bounds of camera, x, y, etc
Now with that you can create some "collisions" which you will use to determinate when you camera should stop and when continue to follow something
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: How to clamp camera?
It seems StalkerX has a setBounds(x,y,w,h) method, but it only works properly when the scale is 1? Problem?
Re: How to clamp camera?
Formally I think this is called a 'filter'.
You have an input 2D point, scale, rotation etc. that you want the camera to assume for the current frame, you can call this the "frame transform". Before applying this frame transform to the camera, you send it to that filter function and it will return a transform, which can be the same one (pass-through, no changes) or it can be a new transform with some components constrained according to some rules that you decided.
You get to decide what kind of constraints you want the camera transform to follow, and program the filter function to enforce them: boundary constraints (camera center is limited to the region of a rectangle), or collision, or a preset path for an "on-rails" camera, or the camera needs to always include 'these' objects on screen (so its scale and position are constrained to include those objects) etc.
You have an input 2D point, scale, rotation etc. that you want the camera to assume for the current frame, you can call this the "frame transform". Before applying this frame transform to the camera, you send it to that filter function and it will return a transform, which can be the same one (pass-through, no changes) or it can be a new transform with some components constrained according to some rules that you decided.
You get to decide what kind of constraints you want the camera transform to follow, and program the filter function to enforce them: boundary constraints (camera center is limited to the region of a rectangle), or collision, or a preset path for an "on-rails" camera, or the camera needs to always include 'these' objects on screen (so its scale and position are constrained to include those objects) etc.
Code: Select all
local frameCameraTransform = camera.createTransform(x, y, scale, rotation)
local constrainedCameraTransform = camera.constrain(frameCameraTransform, gameContext)
camera.setTransform(constrainedCameraTransform)
Who is online
Users browsing this forum: No registered users and 4 guests