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 / Trouble with gravity and player movement with Sparky's Collision

Author
Message
Yodaman Jer
User Banned
Posted: 22nd Oct 2010 21:44
This one's been puzzling me for a couple of days now.

Recently I started learning Sparky's Collision dll as someone told me it was not only good for collision (which it's AMAZING at!), but that it could help me create gravity for my games.

I checked out the Sliding Demo that comes with Sparky's, and I played around with it a bit to get the hang of modifying variables and seeing the results. Everything worked fine.

Then I tried to code it myself (but I cheated and looked at the Sliding Demo's source file ) to help keep the techniques permanently burned into my brain, however, I have two problems.

First, using WASD to move, the player object does not stop moving after the player has let go of the keys. The object just keeps flying until it reaches the end of the ground object and then falls forever.

Second, my jumping code doesn't seem to work. I figured out how to use the Jump Timer variable from the original Sliding Demo to create a triple-jump, but when I implemented the very same code into my own program, it didn't work. And the jump looks very hard and it's not at all smooth like in the original demo.

Here is my code...please copy>paste and run it in your DBPro compiler:



Here's the original (but modified) version of the Sliding Demo for comparison...for some reason some of the formatting got messed up when I opened it up in Notepad. Sorry.



So what am I doing wrong? How come it works fine for Sparky but doesn't work for me? Am I overlooking something or updating something wrong?

Thanks to any and all who help me figure this out!

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 22nd Oct 2010 23:30 Edited at: 22nd Oct 2010 23:31
Just a simple typo.

Look above your chunk of code that handles your WASD movement: You put in:



You're zeroing your X and Y velocities, when you should be zeroing your X and Z velocities.



That one bit is what's causing both of your errors - Before, you weren't zeroing your Z velocity, so you'd quickly speed off into oblivion. At the same time, you WERE zeroing out your Y velocity every cycle, which was why your jumping was awkward.
Yodaman Jer
User Banned
Posted: 23rd Oct 2010 00:02
...Oh. That's embarrassing. xD

Thanks gbark! I must've just got the variables Vy# and Vz# confused in my head.

And to think I was wracking my brains for two days! This is why I love this forum; people are actually willing to read others' code and help them out, even if it's just a simple typo.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Oct 2010 00:43
Glad sparky's is working out for you

it gets harder when you don't look at the demo

Yodaman Jer
User Banned
Posted: 23rd Oct 2010 00:58
Quote: "it gets harder when you don't look at the demo "


Hehe, yeah, that's why I've re-coded it a few times to try and help make sure I remember how to do it on my own next time.

I figure that now is the best time to try my hand at making a simple game to test out gravity on multiple objects and basic, polygonal collision detection with the use of SC_SetupComplexObject. In fact I'm gonna start work on it right now.

Login to post a reply

Server time is: 2026-07-22 03:51:44
Your offset time is: 2026-07-22 03:51:44