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 Physics & Dark A.I. & Dark Dynamix / WASD with dark physics character controller?

Author
Message
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 25th Feb 2008 00:49 Edited at: 25th Feb 2008 02:24
I've searched the forums, helpfiles and examples, but can't find anywhere that uses the character controller for WASD movement.

I think this is because the "character controller" can only be moved forward, not sideways, so strafing is not possible.

The alternative seems to be to use a kinematic object for the player, and do it all myself - is this the best way? (eg general Reed's post in pinned topic)

Yet another game programmer
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 25th Feb 2008 12:16 Edited at: 25th Feb 2008 12:17
To move the character controller in a strafing motion, I rotate the character controller to face the direction you wish to strafe (i.e. left by 90.0 or right by 90.0) then move it by the required amount then rotate it back. Then, obviously you move the character controller forward or backwards for normal movement (if needed).

EDIT: Edited to clarify.

Projects Started: 20
Projects Completed: 0
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 25th Feb 2008 14:52
Note: I've read posts where they say the character controller is a "Get you Started" kind of thing - and people resorting to making there own is not uncommon.

So you may need to if the above suggestion isn't workable.

Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 26th Feb 2008 17:25 Edited at: 1st Mar 2008 14:32
[Edit: Got it working: I was right I was doing something dumb]

Here's how I'm doing WASD with the character controller, in case anyone else Googles for the topic title. Headbob, Jump (with ceiling and floor collision and veocity tracking), Gravity, Analog Crouching, Auto-Crouch, Auto-Stand, Third-Person camera are in too, as well as the normal Player Controller stuff like sliding collision, etc. The player speed and jump height and stuff is configurably affectable by ducking, running, strafing, etc.

Bugs:
1) When using the third person camera it does not respect mesh collision.

2) When climbing steps the camera is not smoothed.

3) When using mouselook, the camera is not smoothed.

4) A better system than raycasting is needed for auto-stand. In certain circumstances you can stand when under the corner of a table and have all of the rays miss the corner. Then you get pushed into the ground as you stretch.

Other than that, it works, prettymuch. I'll edit this post as I fix these remaining bugs.

Sorry to those who asked for a no-media version of the code: I have instead attached a full version, with source, media and compiled code. 3.8Mb.

This code is in the public domain and may be used in any way you wish, however, the media is probably Copyright to the 3D World Studio people.

Yet another game programmer

Attachments

Login to view attachments
Pixel Perfect
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: UK
Posted: 26th Feb 2008 21:25 Edited at: 26th Feb 2008 21:26
Quote: "Gravity isn't working on the player object - anyone know why?"


As far as I can make out gravity doesn't work on the player object because the character controller is deliberately divorced from the physics engine by design to avoid the pitfalls often associated with using physics to control character movement. As you point out, there does seem to be some simulated downward movement applied by default but it's not acceleration. Effective jumping and falling will require simulation of acceleration and de-acceleration or conversely I guess you could link the character controller actively in to the physics simulation at those points to allow gravity to take its effect.

No matter how good your code is, someone will improve on it
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 26th Feb 2008 21:42
So, the only thing the player controller gives us is some collision detection? I suppose I can see why people don't use it, then.

There may be pitfalls, but the most important thing to apply physics to in a game is often the player. At least gravity.

I tried adding the controller to the physics once ("phy make rigid body dynamic box PLAYER.Object"), and it promptly fell through the floor. I'll try again and see whether I can figure out what went wrong. Or maybe I'll just track player global vertical velocity. It might be easier.

Yet another game programmer
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Feb 2008 22:59
(Start higher off ground) Try 3rd person cam to get it working too... If I stated the obvious - I'm sorry - just thoughts I figured I'd post.

Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 26th Feb 2008 23:16 Edited at: 29th Feb 2008 10:29
Doesn't fall through floor any more, so I guess whatever I was doing wrong, I'm not doing it anymore. [Edit: deleted waffle]

Yet another game programmer
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 29th Feb 2008 10:44
Updated my code above to show how far I've got so far.

I'm pretty happy with it at the moment, the features remaining to implement are just "gravy", and none look impossible.

Features implemented:

* Forward, back, strafe left/right, turn left/right. Typical WASD stuff.
* Crouch - changes height of the character controller smoothly over time (set speed with PLAYER.CrouchSpeed#). Crouching can be configured to affect a number of things including walk speed, jump height, and bob height.
* Gravity - player falls at the correct (configurable) acceleration.
* Jump - Correctly collides with ceiling and floor. Can only jump when standing on something, not while jumping/falling.
* Third person camera toggle.
* Head bob.

Even discounting blank lines, comments, the userdefined type and setting all the variables (which could all be replaced by constants and globals), this is still 100 lines of code. Counting all that, it's more than twice as long. Seems a bit much, but it does the job.

Would be very interested in people's suggestions for improvements, even just in coding style.

Yet another game programmer
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 1st Mar 2008 14:22 Edited at: 1st Mar 2008 14:23
Updated: now I have autocrouch and autostand in.

Although it basically works, I am *really unhappy* with the raycasting ceiling detection, and would love if there were a way to make volumetric raycasts. This would stop the player from plunging through the floor and falling forever if he stands up in just the wrong spot.

So if anyone can help me with collision detection with the player controller, I would be very grateful.

Yet another game programmer
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 1st Mar 2008 17:30
Dewi
I am unsure what exactly you mean by
Quote: "volumetric raycasts"
but if instead of raycasting in multiple directions, create a sphere or a box, test if for collision and then review the returned colliding objects to determine your next move.

COdger

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 1st Mar 2008 19:03
You could just do a handful of raycasts. Your player is a box, yes? So at each corner of the box do a raycast up and a raycast down. If any one of these returns a value to low for the ceiling, for example, you can prevent the player from standing

Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 1st Mar 2008 21:54
Codger: "volume raycast": a raycast with integer (non-zero) width and/or depth, as well as infinite length. Collision detection would work, if I could get it to work at all. I'll have more of a play.

Airslide: That's exactly what I'm doing at the moment, and there lies the flaw. If the player stands under the corner of a table (or indeed, a branch, plane, spike, stalactite, or stuffed moose head), with the object corner overlapping just the middle of one edge of the box, then the rays cast upwards will miss the object, but the automatic collision detection of the player controller will not. So when I make the player controller taller, it will collide with that object and, as it grows, push the player down into the floor.

I rather feel that I should have a more rigid definition of "floor" anyway. I feel the floor should be *harder* than the ceiling, and that if anything, people should be thrust up through the ceiling, not the floor. Since at least then they won't fall forever. I don't know how to enforce this behaviour though.

Yet another game programmer
Dewi Morgan
16
Years of Service
User Offline
Joined: 16th Jan 2008
Location: London, UK
Posted: 2nd Mar 2008 03:31
Meh - I *only just* found the .chm file. I've been going off the .html files and the examples. The chm adds a few more bits of info. Two in particular caught my eye.

1) All my raycasting problems can be solved with a "placement API" that apparently exists...

"DP Help CHM" wrote: "The character controller commands supports runtime volume updates. However volumes are directly modified without any extra tests, so it might happen that the resulting volume overlaps some geometry nearby. To avoid this you must first use the already existing “placement API” from Dark Physics, to check that the volume of space you want to occupy is actually empty. Then and only then, you can update the character’s volume."


If anyone can tell me more about this "placement API", I'd love it. I can't find any reference to it other than this one comment.

The alternative (other than raycasting which has already proven to be insufficient for auto-stand) is to use a trigger that follows my player's head around, and prevents him rising if something enters it.

2) Character controllers have a "skin":

"DP Help CHM" wrote: "A small skin is maintained around the character's volume, to avoid numerical issues that would otherwise happen if we let it touch other shapes. The size of this skin is user-defined."


It's some kind of "fudge factor", and explains all sorts of things, like why my rays, if fired from too low in the character controller, would hit an object somewhere within the character; and why I keep falling through the floor. But there's no "Phy get skin width" comand, so I can never know how big it is unless I set it myself with "phy set skin width". So that's what I'll now do.

Since it's just there to reduce jitter, I think I should be fine setting it to anything more than the displacement due to gravity per frame. Which means setting the physics objects larger than the real objects by something like (skin/2), so the average interpenetration is 0.

3) I pause my program completely when people alt-tab away. I should be doing something less drastic, so physics can update itself at least, since otherwise when they tab back, everything goes nuts as physics tries to catch up with itself.

Yet another game programmer
sindore
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 2nd Mar 2008 11:06
Iv put out a challenge to any one who is interested,
her is the link

http://forum.thegamecreators.com/?m=forum_view&t=124954&b=30

I hope you come and have a go, If you've got the man lumps

From the dark and in to the light, twisted the body of madness, dark souls to only the one who would be called, Death lord of the dead, king of the forgotten, keep of lost souls.
Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 3rd Mar 2008 21:58
@sindore - NOW SHUT UP WITH THAT CHALLENGE.....!!!

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine (thanks kBessa)
sindore
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 11th Mar 2008 00:52
sorry about that, I wont bring it up any more. my bad

From the dark and in to the light, twisted the body of madness, dark souls to only the one who would be called, Death lord of the dead, king of the forgotten, keep of lost souls.

Login to post a reply

Server time is: 2024-11-24 23:10:24
Your offset time is: 2024-11-24 23:10:24