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 / Sparky collision plugin - hard road to making first person game

Author
Message
Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 29th Nov 2012 00:01 Edited at: 30th Nov 2012 03:10
I'm trying to setup simple FPP game (not shooter though, more like adventure game) using Sparky's collision plugin (default collision system sucks and I don't have money for Nuclear... something - don't remember exact name).

I'm trying to use movement code from Sliding Demo (btw, it works fine so definitely *I* am doing something wrong). Code of main file is here:


File map1.x: http://www.mediafire.com/?hmh2wtnmwsnr7fx - for groundtex.png you can use any dummy 256x256 texture.

Here is also functions and constant definitions code (it is in separate file in order to make project code maintainable):


Mainly it is directly copied from Sliding Demo (with some changes, like dividing player movement speed since player was moving too fast).

The idea is simply to embed camera into invisible sphere (since normals are flipped) so player can move around. Unfortunately even though SC objects are prepared, collisions aren't working, player is phasing through ground and gravity isn't working at all. I don't know what to do.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Nov 2012 22:54
I can only say, start with the example code, and then work from there, piece by piece... I cannot help with SC's code here or look through that code... but for future strategies, start basic, build on top... test at every stage...

Also, perhaps use DropBox, I think MediaFire is completely public, but I could be wrong... alternatively, you could embed up to 50MB on a thread post...

See Attachment below the message box, click browse...

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 30th Nov 2012 03:11
Since I am still on probation, I don't want to clutter TGC server with meaningless files (for most people). Also I really don't care about if someone will get my model file because
-It's a crap
-I gonna release game's code anyway, so...
-There are a lot more of good terrain models and you can make your own with DBP commands, like make terrain or just model from scratch one.

And strategy you suggested was actually employed by me, the only thing I did was separate game's code and function declarations into separate files (it worked fine then), then starting to change it into what I've posted in OP.

Alternatively, if someone could write good FPP movement code with jumping for me (I suck when it comes to physics and collisions - couldn't even employ library that does most of hard work for me), I'd be grateful, but would prefer help in understanding my mistakes so I can learn something (rod vs. fish argument).

Also updated link in OP to be actually clickable (won't appear until mod approve it)
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Nov 2012 09:51
I'll have a closer look at your code once I get home. You might be interested in this for the time being: http://forum.thegamecreators.com/?m=forum_view&t=187644&b=6

TheComet

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 30th Nov 2012 17:35
Thanks for your sample code. I'll do with it what I can, but probably won't be able to do much as I cannot grasp the true form of your code .
I've programmed for c64, ZX Spectrum, Atari ST, but I always HATED datas and gosubs. While I can understand usage of the former (easy well, data, storage), why didn't you use functions anyway? Subroutine is just function that doesn't return any values.
TL;DR; some parts of your code are just unreadable because of use of outdated constructs.

Sorry if I sound offensive or anything like that, but that's who I am - I am always honest and if I see something wrong to me I'm not afraid to speak about it.

Also your code in addition to demonstrate how to make proper collisions themselves demonstrates constructing level along the way which adds to the confusion.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Nov 2012 18:27 Edited at: 30th Nov 2012 18:28
Quote: "Sorry if I sound offensive or anything like that, but that's who I am"


No problem.

I used data statements because there's not a more effective way to display a readable and editable form of data without using external files. Normally I'd use some kind of media to create my levels, but I wanted my code to just run.

I decided to use subroutines over functions because of two reasons.

1) Variables set in subroutines are global, variables set in functions are only local and would be lost once out of scope.
2) There is no data to be passed or returned.

Quote: "Also your code in addition to demonstrate how to make proper collisions themselves demonstrates constructing level along the way which adds to the confusion."


Yes, it demonstrates two things, but one does not need the other in order to gain an understanding of how one works. If you were to ignore the level creation part, or even take it away and just place a cube there instead, nothing would change with the collision section of the code. I see it more of a bonus than confusion.

Possible solution to your problem

This is just a hunch. When you #include a source file, it is simply appended on to the end of your code. What happens with your code is that this section is never executed:



DBP requires to actually execute declarations (unless this has changed with some update I'm not aware of), so you may want to shove that into an init() function of some kind and call it at the very start of your program.

Assuming my theory is correct, the values you calculate in the function movePlayer() are lost every time you exit the function, so make sure every variable you need is either global, or part of a user defined type.

Another thing that jumps out is this line:



Shouldn't that be this?



Or even this, if you prefer not to include the last position of the player into the collision calculation?



I'd also like to note that I don't like the way you're handling the act of jumping by adding an offset to the player's Y axis. You should apply the gravity# force directly to the player's Y position instead. If you were to simplify the method you're using, that's exactly what it would come down to anyway, so why do it the confusing way?

The way you're handling old positions is not normal either. Old positions should not be altered at all. The only purpose of old positions is to keep track of the last frame the player was in, and use that for differential calculations of some kind. Only the new values should be updated. If you take a look at the example code I linked and narrow it down, you'll see that the old positions are only updated once, and the new positions are the ones that determine where the player will be:



I highly suggest you learn how to use user defined types. Here's an example:



It keeps your code organised and easier to maintain, plus you get the benefit of the compiler noticing typos, which you normally don't get if using regular global variables.

TheComet

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 30th Nov 2012 22:42 Edited at: 30th Nov 2012 22:46
Well, code is almost 100% copied from Sparky's Sliding Demo, so any problems with code organization please take to him . I am using custom types to organize my thing better, but this was quick and dirty test.

//edit: and you had right about globals, but now character is falling thru ground. Nevertheless, it's a progress.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 30th Nov 2012 23:01
Darkhog... You have a very peculiar way about your threads... And posts...

Just hope you are simply not good at english... Otherwise I think some may take offence by some of your wordings...

Just a heads up...

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 30th Nov 2012 23:32
I'm not very good at English, had very long pause so, you know...
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2012 00:19
Not to worry, I just wanted to be sure... as some things you phrase sound rude to me, just saying...

Not to worry

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 1st Dec 2012 13:38 Edited at: 1st Dec 2012 13:40
Well, I'm making big use from online dictionaries and (sometimes) even google translate + was pretty tired when I wrote those posts, so it might add up.

//edit: But this is now Off-topic, isn't it? Please delete this and above posts regarding this subject after you'll read it, MrValentine to make this topic clear, ok?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2012 13:49
Try Bing Translator... I gave up on Google about a year ago... ^^

Must be why I found your posts so bad ^^

Darkhog
11
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 2nd Dec 2012 11:34 Edited at: 2nd Dec 2012 12:09
Well, I'm trying to stay away from anything Microsoft, DBP is one of very few reasons I'm still having windoze on my computer. So thank you, for your advice but I probaly won't use it . Anyway, let's get back to topic, ok?

So I've got collisions to work somehow, but on some parts of the model when I walk to, it just fall inside (through level). Here's my current code.
Main file:

functions file:

Attaching Blender's file from which map was generated if something in model is a problem (although I don't really know if it is, the only thing it MIGHT be are concave areas... but regions where player falls through aren't concave).

//edit: Fixed problem... somehow. Don't know how so I can't post solution

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 08:15:32
Your offset time is: 2024-11-24 08:15:32