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.

Newcomers DBPro Corner / Jittery object problem

Author
Message
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 1st May 2009 18:01
So, I'm trying to code some gravity, well, any collisions really. I still haven't figured out why this results in jittering effects of the objects though. I'll just hand the full source out below, it doesn't do much and is mostly stolen from the documentation anyway:



Anyway, the main part I am concerned about is the gravity code. When the program is run, the object keeps "bouncing".

I think what is happening is that DBPro is rendering the movement of the object down, and then instantly rendering it again as it's moved back up, resulting in the twitching. But I don't know how to fix it, as my rendering code is the same as the example's code, which contains a sync command at the end that should result in rendering the game AFTER the movement, not before.

I'd like to add that I clearly have no idea what I am doing. :p It's been several months since I last used DBPro, and it was the autocomplete feature in the recent update that brought me back(I have trouble remembering command syntax, it's a side effect of my medical situation, so this has made it possible for me to actually type stuff without having to look up every command for hours.)

Oh, to test the code, just replace the gordo.x with whatever file you like, it's just a 3d model used to test for now, so it doesn't matter what it is, within reason of course. A giant level model probably won't work well since it'll end up inside the floor. x_x
Encrypto Studios
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: Virginia
Posted: 1st May 2009 19:31
i would suggest to look into the physics engines like sparkys, newton...etc it is a lot easier than trying to code one yourself.

300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 1st May 2009 20:40
How would I use sparky's engine to do a mouse controlled WASD movement? (A lot of recent pc action games have this setup, the mouse rotates and moves the camera around the player, and the player is controlled with wasd based on where the camera is looking.) Last time I looked, the only example was for controlling this orb thing around and the camera followed the orb's angle, which wasn't useful for what I'm trying to do.

I didn't understand most of the code in the example either, so I'm trying to work with what I can understand and build from there. DarkBasic is the first 3d engine I've been able to work with, previously I've been using MMF, which is much more sprite and event/behavoir based instead of having to manage an array of object ids(which might be totally different objects like the level, enemies, collectables, player, ect) like in DarkBasic.

One of my problems is that I have no concept how to set up some sort of system where all enemies can be checked for collision without looping and checking every object in the game, but I'm figuring I can work that out if I can get some objects in 3d space to play with.

Which brings me back full circle to this, why is the object bouncing when each loop it should just appear to stay put?

I tried turning sync off, to see what happened, but the framerate and game dropped to 30 frames a second instead of the normal, smooth rendering it's doing with it on. Not only that, but the object still was jittering.

Hmm, how does the collisions work anyway? Does it just fire the "on collided" check when it is turned on, or does the positioning already take into account the collision(thus making my repositioning on collision useless). I tried removing the if statement loop, but that just made the object fall through the floor. I'm really confused... O_o
Encrypto Studios
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: Virginia
Posted: 1st May 2009 21:19
well if you download the latest version of sparkeys there is a sliding demo with wasd contols and jumping. in newton there is a fps demo with wasd movement,jumping, and shooting

hope this helps
E.S.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd May 2009 15:51
The problem with the code is this line:
position object 1,px,py+gravity,pz

Because you are adding the gravity back onto the original position, you are actually moving it upwards. The next frame it falls back to its original position, then it hits the ground and you bump it back up into the air again.

Change it to this:
position object 1,px,py,pz

IMO, the DBPro collision detection is perfectly OK for this kind of thing. It's only if you need to do something move complex that you should be looking at an alternate collision system or automatic physics.

300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 3rd May 2009 16:31
Thanks, that worked. Thank you for the explanation as well, I didn't realize that the px/y/z wouldn't be updated till the next loop. :p I must have been asleep or something.

Yeah, most of this project is going to be just simple collision using the default box/spheres, so I agree that Sparky's is a bit overkill. I'm not trying to make a shiny game, just something to test out how making stuff in DBPro works.

I did get sparky's collision dll anyway, just cause I might use it when I get better at DBPro.

Thanks everyone!

Login to post a reply

Server time is: 2024-11-24 08:56:41
Your offset time is: 2024-11-24 08:56:41