C++ Camera/Collision Detection Problem

Hi guys

Still working with SDL2 and c++ my map collision is messed up since I implemented my Camera.

I do understand that everything has a relative Position on the Screen, depending on the camera.

Problem No. 1:
The camera is not moving as fast as the Player, despite having the absolutly same velocity (4/-4)??? How can this be O_o

Problem No. 2:
My tile collision is totally messed now. Probably its because of the difference between the Player Position and the camera :/ So if you can solve Problem no. 1, Problem number 2 might work out on its own :)

I will upload the code to github any Minute...

EDIT: https://github.com/HalfNOoBee/Collision-Problem

Greets HalfNOoB
Last edited on
Are you actually moving the tiles themselves, are are you just changing where they are drawn? If the former, do the latter. The positions of objects should not change depending on the camera.
Well (in my opinion) I'm only moving the Destination rectangle of the tiles, as soon as I know that there has been no collision with a wall from the Player.


This code you can find in my CMap.h-file in the render-function...

1
2
3
4
5
6
7
8
else if (TileList[ID].GetTileID() == 1) //
                {
                    TileSheet.SetSourceRect(0, 0, Tile.GetSize(), Tile.GetSize());
                    TileSheet.SetDestinationRect (X * Tile.GetSize() - CCamera::Camera.GetPosX(), Y * Tile.GetSize(), Tile.GetSize(), Tile.GetSize());
                    TileSheet.Render(pRenderer);
                    ID++;
                    continue;
                }


Probably I should constantly set the camera on Player.GetPosX() - (Game.GetWindowWidth/2) ?
Last edited on
HalfNOoB wrote:
I'm only moving the Destination rectangle of the tiles, as soon as I know that there has been no collision with a wall from the Player.
It is strange to me that within the same sentence you refer to both the camera and collision checks.
Well it is linked ^^'

I dont want the camera to move if my Player is blocked and Walking against a wall right?

So I'm only updating the Position of the camera when there is no collision. The Position of the camera is subtracted from the Position of the tiles every Frame...

You can find that in my messy CPlayer::Update() function...
Last edited on
I think you are thinking about it the wrong way. The player is what moves and collides, and it just so happens that the camera focuses on the player.
Not entirely the camera can be aware of the geometry, especially in 3d third person games, otherwise you get clipping and other unwanted effects. He simply doesn't want to camera to go out of bounds and render nothing. Think of a corner, if the player goes into the corner of a square map, the camera shouldn't be centered on the player, otherwise 3/4 the screen will be empty space. Instead you have the camera positioned such that the entire corner is visible without having any empty space.
Alright so Ill center the camera on the player today. Ill post my next message after I'm done with dat...
@ezchgg: Yes, but seeing as the OPer is currently experiencing weird phenomena, it would be best to take the simple approach first and refine later.
@ezchgg:
Sorry I didnt read your post before I posted mine :o

Well even with a camera centered on the Player its still eazy to tell that the Position of the Camera can't be negative... But for now I'll just try to get the camera centered (Ill be at my home soon and try it out then) and its a case of 2min to Keep the camera in bounds...

Once the camera is working (and the collision as well) I'll create a tile engine cauz I hate the way I'm currently loading the map :s

Anyway, I'll update here as soon as I've implemented the centered camera...

Wow :)

I double checked anything in my Project (or at least i thought so) and in the end all i was missing was to subtract the CameraPosition from my Player :)

I realised that, when my Player disappeard always after 640pixels (exactly my Screen width)

And as I guessed, with this the collision works again (well working is a bit too much, since its got one pretty big bug...)

I think its still on Topic to ask you guys something on my collision detection ;)


As Long as my Player isnt touching a solid tile, and therefore falling (pulled from gravity) just next to a solid tile (let's say on the left Hand side theres a solid tile) if I press 'd' he will bug onto the top of the tile to the Players left...

The Chance for the Player to move on the tile to his left should be over, but while he hasnt touched the ground it somehow is still possible. I have uploaded (sry for poor editing ^^) an Image to make clear what I mean

http://s18.postimg.org/rdqsze1pl/Collision_Bug.png

Thats pretty much the only error that happens but I dunno how to fix it... You can try it out realtime if you want. Ill push the updated documents onto the github repo I posted on top of here in a few minutes.

Thanks for everything so far :)
Anyone? This is a voluntary Project for School making out 100% of my english mark in 6th Semester ^^

And I don't want the game to be sucking because of some bad collision detection with my map and end up getting a bad mark because of that :p

So it be great if any of you finds anything wrong with the collision. If you dont understand what I mean, try running the .exe and jump around. Move to gaps and before touching the ground press a/d in the direction where the tile is...

Thanks in advance
Topic archived. No new replies allowed.