Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    5
  • comments
    15
  • views
    1145

PC Camera and platform Update

lilington

1002 views

Hello,

It's been a while. I was busy again with other stuff but I managed to work on the game engine (less on the game itself) during this time. The new features are not visible for most of them, it is more about code optimization and organization. But now we have a better 2D camera system that I will present right now.

The first nice thing is how to use the camera. I just need to initialize, choose among some functions and call the camera update function it in the game loop.

void bkp_graphics_2DinitCamera(BKP_Rect dim, BKP_Rect world,int camera_function); //Initialize
int bkp_graphics_camera2D(BKP_Dynamics2D P); 							//Call in main loop to follow the scene

void bkp_graphics_2DsetCameraDim(BKP_Rect dim); 			//obsolete
void bkp_graphics_2DsetCameraWorld( BKP_Rect world);		//world limits (up,left,down,right)
void bkp_graphics_2DsetCameraAuto(float auto_speed);		//obsolete use camera2DsetFunc() instead                   
void bkp_graphics_2DsetCameraSpeed(BKP_Vec2 speed);         //set a speed other than default
void bkp_graphics_2DsetCameraPanic(float up, float down);   //set the panic lines for vertical scroll IMPORTANT

void bkp_graphics_2DtoggleCamera(void);                   //Freeze the camera to the current position or unfreeze

void bkp_graphics_camera2DsetFunc(int function);			//select a camera function 

Basically, there are only 2 mandatory functions, others are used to change the default values for the camera function, focus or speed. There are more than listed here. Yes, it is possible to change the camera function during the game. Here is an example of how to use it:

BKP_Rect world = setMapPlatform(); 


bkp_graphics_2DinitCamera(bkp_rect(g_scr.w / 4, g_scr.h * 2 / 5, 0.0f, 0.0f), world, BKP_CAMERAFUNC_SMOOTHSTD);
bkp_graphics_2DsetCameraPanic(150,50);
bkp_graphics_camera2DsetFunc(BKP_CAMERAFUNC_FOCUS); 

while(Player->input->Cancel == 0)                                                                                                                                                                                                                                            
{
        bkp_input_capture(Player->input);

        manage_player();
        bkp_graphics_camera2D(Player->dyn);

        Ugp_draw();
        _update_fps_counter( fps); //print on the screen FPS and Memory usage
        _update_memUsage(mem);

}

1/get the world dimension from the level layout.

2/ select smoothstd function for scrolling
3/set the up panic at 150 pixels under the top of the screen and 50 over the bottom of the screen
4/we change the current function to FOCUS to tell the camera to scroll to the target instead of just show the player in the centre (look at the beginning of the 2nd video to see the scrolling animation to find the player). The camera will switch  automatically to the function passed in 2DinitCamera as soon as the target is locked.
By using BKP_CAMERAFUNC_FIXEDSETFOCUS,  we will set the camera without scrolling the prior animation to find the player.

I organized the code in the way that it is easy to add a new camera function without modification in the game loop. let's have a look. Actually the bkp_graphics_camera2D() is that simple:

int bkp_graphics_camera2D(BKP_Dynamics2D P)                                                                                                                                                                                                                                    
{
    int ret = camera2D(&stc_2D->camera, P);
    if(BKP_TRUE == ret)
    {
        bkp_graphics_2DsetCameraSpeed(stc_2D->camera.delta);
        bkp_graphics_2DTranslateView(stc_2D->camera.speed); // manual
    }
    return ret;
}

int camera2D(BKP_Camera * S, BKP_Dynamics2D P)
{
    if(S->on == BKP_FALSE)				//set or unset by toggle()
        return BKP_FALSE;

    return TBL_Camera[S->func](S, P);   //all functions are in this table
}

Notice that I pass a BKP_Dynamics2D structure to the camera instead of anything else not general, all objects I want to get focused by the camera should have a BKP_Dynamics2D structure. That's it, Player, NPC, or whatever object so far has that. it is a simple structure with position, dimension, ...

So, next time I want to add a new camera I just have to create the function and set a new entry in the enum of camera functions et voila, nothing to change, just add.

LOCKON camera

 

 

 It is just a basic camera where the player is centred everytime it is possible. For horizontal movements it is ok but when it comes to jumps it starts to hurt our eyes. I did it at the beginning just to be able to test the collisions and travel around the map.  This camera function is not really usable to play a platform game. 

 

STDsmooth camera

 

This function solves the problem with vertical scrolling and smoothly scroll. when changing the direction we can notice the camera scroll to give us some room in the direction the player is facing. On vertical movement, the Camera scrolls only the player is on a platform or if he is going to high (on the video the orange line)

 

here let see the differences between the two functions on vertical movements.(sorry for the gif, gimp decided to annoy me) . You can see on the left gif the player jumping without the camera moving while on the right gif it moves everytime the player move up

focusy_optimzed_.gif.2dba55b9b15d27dd7c12a8bbce3e8c0c.giflocky_optimzed_.gif.03e8fdcdef48f941ce6ba0525574c30b.gif

The lockon camera is used in Soul of Mask, but I keep it here because this is the choice I made for autoscrolling. I made a function auto scroll before which is obsolete (or not, maybe I will delete it maybe not) and replace by the Lockon camera. I just ask the camera to follow a target different than the player. Here on this video, you will see a green square moving around. The camera will use this green scare as a target, that's it I have an auto scroll now:

 

Coming up next:

 I will stop the game engine and go back to the game development again, the next time we should have the first image of the game.

Thanks for reading. Any technical questions ? don't hesitate. I decided to release the engine part on Github and only keep the game part proprietary.

 

 

 

 

 



2 Comments


Recommended Comments

Welcome back, looking forward to seeing more progress on your game. :) 

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • What is your GameDev Story?

    In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

    (You must login to your GameDev.net account.)

  • Blog Entries

  • Similar Content

    • By Rof
      Hello guys! I am new to Unity3D and also new with C#. I am currently working on a 2D Platformer game. This would be my first game ever. I really need some help in coding and animation. I was able to create script already for my Player Movement. I already have the basics coded and working (Walking, Jumping, Attack, Dash). I also have an extra feature which allows the player to jump longer if he/she presses Space for a longer period of time.

      I just need help in fixing the Jump + Attack. Whenever the player Jumps and Attacks at the same time, the character will ignore the x velocity of the object and will only continue the x velocity after the attack animation.

      I'll really appreciate any help that you can give me 
      Have a great day!
    • By snacktime
      Looking for feedback from someone who has done this, mainly just to confirm that my guestimates are not way off.  I know enough to be dangerous not my area of expertise.
      Trying to budget for a custom 3D skeletal animation system with cross fading and 2 layer blending.  Context is Unity.
      My thought is someone who has done it before could probably get the core features working in some form in a month.  But by the time you factor in everything like bugs, performance refactors, platform specific gotcha's, whatever, it's probably around a 6 month job to get something actually usable in game.
      Does that sound reasonable?
       
       
       
       
       
       
       
    • By RoKabium Games
      Which one of the 4 menus in SAMA is your favourite? 1, 2, 3 or 4?
    • By horror_man
      Hello, I'm currently searching for additional talented and passionate members for our team that's creating a small horror game.
       
      About the game: The game would be a small sci-fi/post-apocalyptic survival horror 3D game with FPS (First person shooter) mechanics and an original setting and story based in a book (which I'm writing) scene, where a group of prisoners are left behind in an abandoned underground facility. It would play similar to Dead Space combined with Penumbra and SCP: Secret Laboratory, with the option of playing solo or multiplayer.
       
      Engine that'd be used to create the game: Unity
       
      About me: I'm a music composer with 4 years of experience and I'm fairly new in this game development world, and I'm currently leading the team that'd be creating this beautiful and horrifying game. I decided that making the book which I'm writing into a game would be really cool, and I got more motivated about doing so some time ago when I got a bunch of expensive Unity assets for a very low price. However, I researched about how to do things right in game development so I reduced the scope of it as much as I could so that's why this game is really based in a scene of the book and not the entire thing. Also I'm currently learning how to use Unity and learning how to program.
       
      Our team right now consists of: Me (Game Designer, Creator, Music Composer, Writer), 3 3D Modelers, 2 Game Programmers, 1 Sound Effect Designer, 1 Concept Artist, 1 3D Animator and 1 Community Manager.
       
      Who am I looking for: We are looking for a talented and passionate programmer that's experienced with Unity and C#.
       
      Right now the game is in mid-early development and you can see more information about it and follow our progress in our game jolt page here: https://gamejolt.com/games/devilspunishment/391190 . We expect to finish some sort of prototype in 3 months from now.
       
      This is a contract rev-share position
       
      If you are interested in joining, contributing or have questions about the project then let's talk. You can message me in Discord: world_creator#9524
    • By Canadian_Goose
      Hello, 
      I am part of a team with an online PvP game. We get good buzz when we post our work and had a major publisher reach out to us and casually express interest in our work a while back. We finally have a stable build and are about to present to them our work thus far!
      It is very exciting, but also nerve-wracking, because our game development experience is very limited. So with that in mind...
      What the heck is a good publishing deal for an indie studio like us? There is frustratingly little information on this specific question, and what I find is all over the place. Here are examples of what I've read are "typical" deals:
      The publisher handles all marketing expenses and takes a 70% cut of the revenue, leaving the studio with 30%. The studio keeps the IP and assets. The publisher handles all marketing expenses and takes 100% of the earnings until the marketing budget is recouped. After this point, the publisher takes a 30% cut, and the developers get 70%. The developer pays 25% of the cost of developing the game and the publisher splits the revenue with them. The developer doesn't make much money after the sale of the game. Instead, they should negotiate as large of a budget as possible to the publisher and use as little of it as possible in developing the game. These deals are all over the place! 
      We have so many questions of our own:
      How much of the budget should the developer expect the publisher to pay? (Is this a major reason to partner with a publisher, or is it really for their marketing spend/connections?) Will the publisher expect us to quit our full time jobs to work on this?  Should the devs be asking for any salary at all? Maybe just enough to keep a roof over our heads?  What assets should we expect to keep - our source code, at the very least? Should the publishers buy us out for the work we've done this far, or is that just "written off" as the cost of getting a vertical slice demo?  How do we decide what's a reasonable marketing budget, development budget, and revenue split with the publisher?  Is there a good rule of thumb for how much money should be spent on budget vs. marketing? (I know the marketing expense is significantly higher than the production costs for Hollywood movies, for example) We have funding for another year without a publisher. It is our own money. We would rather not use it, but should we consider using it as a negotiating chip to increase our revenue take, or is that weird? It is scary looking at the digital distribution channels' takes (especially Steam) and licensing fees on top of the publisher's take. We do not want to lose our shirts... in fact, our game is fun and we want to make money! 
      Thank you in advance!
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!