Camera Issue from Game World Chapter

Home Forums Books Mastering Unity 2D Game Development Camera Issue from Game World Chapter

This topic contains 6 replies, has 2 voices, and was last updated by  Simon (darkside) Jackson 2 years, 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9640

    Adam Roberts

    When I go to run the game after the camera following script is complete, I’m getting a stuttering effect. It kicks in a after a moment or two and then lasts after I release the arrow keys for a bit.

    For reference, here’s the code as I copied it down from the book…I’ve triple-checked and can’t find any errors. Using Unity 5.3.4, on a mac

    #9641

    Adam Roberts

    Sorry…the formatting is horrid…lets try the code again…

     

     

    #9642

    Adam Roberts

    And after all that, I figured it out. It was a problem in the variables I was setting in the MainCamera Inspector.

    Problem solved!

    #9653

    Glad to hear you got it working.  I had replied but it got lost somewhere, so great to hear you solved your own problem 😀

    Hmm, there’s supposed to be a code pasting option in the forums, so I’ll have to check what’s going on there.  Usually it’s easier to put in pastebin or other code sharing site and then send the link.  Just makes life easier 😀

    Or better yet, pm me the assets folder of the project (if you can) so I get the full picture 😀

     

    Good luck on your gamedev adventure and thanks for supporting my works.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #10031

    Jason

    Could you possibly explain why after implementing the changes to the camera in “A Better Follow Camera Script” I end up having to divide the minXAndY and maxXAndY by 2 in the clamp function in order to get the camera to stop at the edges of the background image? If I leave it the way it is in the book, the camera stops moving only after allowing the background to go half-way off the screen.

    Is this because the transform position of the camera is the center of the camera view?

    #10032

    Jason

    Sorry, I failed to use the code tags

    Is this because the transform position of the camera is the center of the camera view?

    #10035

    What I’d suggest is downloading the source for the book and comparing your implementation to the final output.

    I’m guessing something is amis with your setup as in the final project you don’t need to apply such a fix.

    Alternatively, zip your assets folder and send me a link and I’ll have a look at what is going on.

    The bounds of the viewable area are defined by the dimensions of the background texture (min / max) and the camera bounds (resolved using ViewportToWorldPoint)

    Then in the final part of the FixedUpdate function, we simply clamp the final position of the camera (which follows the player) within these values.

     

    Hope this helps.

    Simon (Darkside) Jackson
    @SimonDarksideJ

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.