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.

DarkBASIC Professional Discussion / Camera Physics, Help Needed

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 2nd Feb 2011 21:27
I'm working on an FPS and I found that the best way to have physics for the camera is to use sliding box collision. The new positions for the collision set the velocities of the camera. Then the velocities are added to the camera position.
First, how do I calculate sliding box positions?
Second, what would be the equation to apply gravity to the Y velocity of the camera?

My computer surpasses all the technologies of the day. What computer do I have?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Feb 2011 12:14
Two searches you need to try in the search bar at the bottom of the page.

1-"Massive Collision"
2-"Gravity"

There are thousands of threads on the subject of gravity and the first search will tell you everything you need to know about sliding collision.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 5th Feb 2011 23:53 Edited at: 7th Feb 2011 02:37
Thanks, the massive collision helped a bunch.
But... the method for sliding collision does not work 100%
Say I have my player walk into a surface, the collision process is

This works fine for collisions when an object is moving on just one axis at a time, but if the object was moving on a diagonal the only solution found would to move back on the first axis on which collision was checked, which would not always be correct. So what's the workaround?? Would I have to check every possible solution (there would be 15 total)?
There must be an algorithm for this.

I read some threads on gravity. I know that the accelleration increases the vellocity and that increases the positions. But how does the 9.81 accelleration come to play? Does the accelleration increase until it gets to 9.81 when the object is falling?

My computer surpasses all the technologies of the day. What computer do I have?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 10:38
I tend to use sparky's collision as it saves you a lot of the hassle of working out algorithms like yours. It returns sliding collision positions for you.

Quote: "I read some threads on gravity. I know that the accelleration increases the vellocity and that increases the positions. But how does the 9.81 accelleration come to play? Does the accelleration increase until it gets to 9.81 when the object is falling?"

I tend to do it like this:


Hope that helps!

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Feb 2011 14:58
But isn't that sliding collision limited to spheres? That would mean that I would I have to have 2 spheres, one for the top of the player, one for the bottom.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 15:05
Quote: "But isn't that sliding collision limited to spheres? That would mean that I would I have to have 2 spheres, one for the top of the player, one for the bottom."

Yes, I've done it like that before and it worked really well and very quickly. You can try it out here:
http://forum.thegamecreators.com/?m=forum_view&t=169135&b=8

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Feb 2011 15:27 Edited at: 7th Feb 2011 15:27
Okay, thanks but I now have another problem.
With 2 spheres, the collision response is weird. I set the bottom sphere (3 units below the camera, radius of 3) to only calculate the Y slide position so that the player doesn't slide down slopes on the ground. Then I made another collision sphere (3 units above the camera, radius 3). These spheres shouldn't interfere because they don't intersect. But the camera starts bouncing up and down.


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 15:40 Edited at: 7th Feb 2011 15:46
Without seeing what your function calls do and what your values are it's a bit like guesswork.

Why not post a simple demo example? I'll hunt my code out for "The Waystation" and post it here if I have it handy...

EDIT: Here it is...


Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Feb 2011 16:07
I tried writing an accurate example to show my problem but it didn't work so I'll just post my code above simplified.
(your example uses a different method than mine so it's very hard to apply because I would have to change a bunch of my current code)


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 16:17
Try this instead:


Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 7th Feb 2011 16:18
Worked like a charm, thanks a lot.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 17:54
Pleasure!

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 8th Feb 2011 03:35 Edited at: 8th Feb 2011 03:53
Ok, now I'm implementing jumping. I got the basics working but it isn't realistic looking. What I'm doing is having a y velocity that is set to a positive number when space is pressed. This velocity is added to the Y position each loop and also decreased to account for gravity. But because the Y velocity is suddenly changed positive, the initial part of the jump is "blocky". Now what would be a way to have smoother jumping?


EDIT:
Nevermind, I figured it out. What I did create a Acceleration variable. Each loop, this was added to the velocities and the velocities added to the positions. Then I multiplied the accelerations each loop with a decimal value to give air friction. Then, if the player wasn't touching the ground, I decreased the acceleration until it reached a certain negative value creating gravity. So when the player jumped, I set the Y acc to a positive number, which smoothly incremented the y velocity.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Feb 2011 10:43
Great, glad to hear you worked it out. Sounds like you're getting the hang of it now

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 8th Feb 2011 18:33
Yeah, I'm basically trying to program an entire engine for a game. It's the largest most complicated thing I'm writing.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Feb 2011 21:43
Very satisfying though. Good luck!

Login to post a reply

Server time is: 2026-07-15 22:38:13
Your offset time is: 2026-07-15 22:38:13