Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Over-the-shoulder camera collision

Author
Message
Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 20th May 2011 08:58 Edited at: 20th May 2011 09:01
I am trying to achieve a Mass Effect style over-the-shoulder camera in my game. Here is the code I have to position the camera over the player character object's "shoulder":



And this is the code for the player character object's sliding collision:



That all works beautifully. However, there was nothing to stop the camera from passing through the walls of the level, so you could see right through them. I added this camera collision code to prevent that:



That sort of works, but not very well. The camera often jumps around weirdly and gets stuck on the walls.

There has to be a better way of doing this. Can anyone help?

Here is the entire code, if that helps. It's big, and it's got a lot of other completely unrelated stuff, but it still may be helpful.



Hail to the king baby
I love Evil Dead.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 20th May 2011 13:03
Have you tried raycasting?

Perhaps a ray from just above the characters shoulder, backwards by the desired distance, if it hits something then place at that position, if not, place it exactly where you want it.

I have never done this so its just a theory.

Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 22nd May 2011 06:14 Edited at: 22nd May 2011 06:15
I tried raycasting, and it didn't jump around as much as the sliding collision method or get stuck on the wall. However, it failed to prevent the camera from clipping with the wall. I threw together this little diagram in Microsoft Paint to illustrate why it didn't work:



Hail to the king baby
I love Evil Dead.

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd May 2011 13:42
Does Sparkys have sphere casting? I think I seen this somewhere.

Casting a shape instead of a ray may solve this issue, let us now how you get on as I guess this is a very common problem.

Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 24th May 2011 07:33 Edited at: 24th May 2011 07:37
Spherecasting did the trick. Here is the camera collision code:



And here is the entire code:



Using this Dark GDK command also really helped:



Hail to the king baby
I love Evil Dead.
Benjames8
14
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 3rd Jun 2011 22:41
keeping the ray cast and setting the camera just before the collision might save some computing power, for better fps. Although I also used the sphere casting when I did that sorta thing..

Login to post a reply

Server time is: 2024-10-02 17:28:02
Your offset time is: 2024-10-02 17:28:02