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 Discussion / Drawing a Shadow Plane?

Author
Message
Yodaman Jer
User Banned
Posted: 13th Mar 2009 02:37
Hello all!

Back in January I was working on a game called Coins Galore (which I unfortunately had to abandon) and posted a thread about it in the WIP boards. When someone (I believe it was a person named draknir_) was offering feedback they suggested I use a 'Shadow Plane' to make depth of perception easier for the player. The problem is I have no idea how to go about this. I even did a few forum searches, but I couldn't find anything very helpful because it was mostly DBPro threads that came up.

Does anyone know of a way to do this effect or know of a tutorial anywhere? Any help will be appreciated, as I want to implement this in my next game.



Check out my programming blog!
Yodaman Jer
User Banned
Posted: 13th Mar 2009 17:41
OK, I'll try and be more specific here.

In games they have shadows beneath all of the characters, especially the player. Here's an example screen shot from Super Mario 64:



You can see the shadow underneath Mario. This is the effect I need to know how to do, and I was wondering if anybody knew of any tutorials that could show me. I've tried both Google and searching the forums, all to no avail. Can someone please help me?

Thanks.



Check out my programming blog!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Mar 2009 18:07
If I understand what is being suggested correctly, then the idea is to make a shadow underneath or next to the object(s) in question. DBC doesn't cast shadows (though depending on the setting of the Normals for an object or matrix a shadowy area is possible) so you have to fake it using drawings or other objects. If you make a plain, and put a filled dark circle on it, lay the plain flat, turn on transparency or ghosting, and place the plain under the object, it can fake a shadow.



Enjoy your day.
Yodaman Jer
User Banned
Posted: 13th Mar 2009 18:22 Edited at: 13th Mar 2009 18:27
That works...until I try to move the shadow with the player.

Thanks for that example Latch, but do you have any suggestions for moving the shadow with the player? The following code will run, and it's really nothing more than a program loop copied from the codebase and modified accordingly (had to remove gravity variables).

Any suggestions for moving the shadow with the player accurately?



Forgot to ask, is there also a way to check and see what platform the shadow is on? For example, I might have several platforms at varying heights, and it would look weird if the shadow was beneath the player while jumping over a gap. Is there a way to prevent that?



Check out my programming blog!
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 13th Mar 2009 19:02
why not:



note that is one code, put that into ur main loop and it will update the shadow's location to the player's, however if the player is in the air then it will show up on their feet, so u may need to expand on this idea
Yodaman Jer
User Banned
Posted: 13th Mar 2009 19:46
OK, after some modification that code helped keep the shadow underneath the player pretty well. I even gave the code gravity.


I'm still wondering, how would one make it so that the shadow only appears on the platforms and doesn't jump with the player. Is there a way one can check to see if the player is touching a platform and if they are, can the check then position the shadow underneath the player?

Thanks for the help thus far guys, it's really awesome. Shadows are a lot of fun.



Check out my programming blog!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Mar 2009 20:53
That1Smart Guy has the right idea. Assuming 3d and y is up, the shadow should follow the X and Z position of the object. The height of the shadow can be determined by the ground height beneath the character. If the ground is a matrix, then the shadows y is the ground height and tilt (if any). If the ground below the character is an object, you can use collision to find the y height or you could use the ground object's position (say, if it was a flat platform) + 1/2 the y size of the ground object (assuming the pivot point of the ground object is at it's center).

If you read through my get ground height and tilt post, you can adapt the techniques to calculate the height underneath the character or the camera and the tilt of the shadow if necessary.

As your character goes up from the surface (like in a jump), the shadow should shrink. If you base the size of the shadow on how large the distance is between the character and the ground at any given time, then the shadow should grow and shrink appropriately. The minimum scale being 0 where the shadow wouldn't be visible at all.

Also, you'll notice I used set object ambient for the plain. This is because I used dark ghosting (ghost object on 1,1). In DBC 1.20, if I don't set the object ambient to set object ambient 1,rgb(255,255,255) for the shadow, you'll see the squareness of the plain because of how the material behaves with the lighting. I don't think this is an issue with DBC 1.13.

If you use a round shadow, you won't need to rotate it (except if you tilt it on a sloping surface). Even if it was oval, you wouldn't rotate it because generally light sources are consistant. If you change the direction from which the light source emits, then you would probably want to change the angle of an oval shaped shadow.

This example shows how to cast the shadow on a matrix. Steer with the mouse, move forward and backward with the arrow keys. Lift the sphere into the air with the left click. The same principals can be applied to a world built with objects instead of a matrix.



Enjoy your day.
Yodaman Jer
User Banned
Posted: 13th Mar 2009 21:50
Thanks Latch!! I can't quite figure out how to make it tilt with just objects instead of a matrix, but I'm sure I'll get it eventually.

Thanks again!



Check out my programming blog!
Yodaman Jer
User Banned
Posted: 13th Mar 2009 23:35
@Latch:
I tried my hardest to modify your tilting code so that it would work with platforms, but to no avail. While it would run the program without any errors, it just wouldn't do anything tilt-wise.

I tried removing this code (position object 2, object position x(1), object position y(1)-.4, object position z(1)), but that resulted in the shadow completely disappearing.

Here's the entirety of the code, remed to make it easier to read in areas:



I remed out the last two lines of code in the function because it would rotate the plain so that it was 90 degrees vertical of where it should have been. It was like this | instead of this _.

Any ideas? I'm sorry for bugging everyone about this, but I feel like I'm really close to finally learning how to do this successfully.



Check out my programming blog!
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 14th Mar 2009 00:14
Try setting the plane's y to the object below the player: it looks kind of strange to see your shadow following you...and colliding with you in midair.

~QJ
That's what they WANT you to think...
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 14th Mar 2009 00:22 Edited at: 14th Mar 2009 00:30
it might be slow but the only idea i can come up with is this:



written from memory so i cant guarantee itll work

another thought, if u want a round shadow why not take either a cylinder or a sphere and flatten it?
Yodaman Jer
User Banned
Posted: 14th Mar 2009 00:55 Edited at: 14th Mar 2009 01:09
Quote: "if u want a round shadow why not take either a cylinder or a sphere and flatten it? "


Too many polygons.

EDIT: Never mind, I solved the issue. Here's the code, it works perfectly and I'm very happy with it!! Thanks to all who helped!





Check out my programming blog!
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 14th Mar 2009 01:11
tell me where the error is pointing to, thatll give me a better idea of the problem is, also i dont have DB until my DGS comes in in 2 weeks
Yodaman Jer
User Banned
Posted: 14th Mar 2009 01:19 Edited at: 14th Mar 2009 01:19
The error was with this line of code: position object shadow,z,y-(.5*object height(player)),z


I replaced 'shadow' and 'player' with the correct numbers and it still gave me the error.



Check out my programming blog!
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 14th Mar 2009 01:21
alright try changing object height(player) in the parenthesis for object y(player) or object size y(player), i dont have DB so i cant check which 1 is right, use the help menu and figure it out, or just try both
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Mar 2009 02:10
@Yodaman Jer
Quote: "@Latch:
I tried my hardest to modify your tilting code so that it would work with platforms, but to no avail. While it would run the program without any errors, it just wouldn't do anything tilt-wise."

The tilt thing requires the y values on the sides and in front and back of the shadow. It looks at all these heights (N S W E) and pivots around according to the angles. It's easier on a matrix - that's why I posted it as an example. For an object, one would have to find the collision heights at N S W E and then figure out the angles to tilt the shadow. No big deal unless you are going to have sloping platforms! The example was also there to show the shadow shrink when you go up a certain height.

At any rate, I'm glad you figured it all out!

Enjoy your day.
Yodaman Jer
User Banned
Posted: 14th Mar 2009 02:25 Edited at: 14th Mar 2009 02:29
Well I figured out how to make a shadow for one level only.

What I mean is that the shadow will only work for blocks that are all on the same Y unit. For example, all of my blocks right now are positioned on the Y axis like so: -1.

While I can get the shadow to draw on that one height with this (position object 2, object position x(1), object position y(3)+2.5, object position z(1)), I can't suddenly re-position the shadow so that's it's on higher platforms.

Right now the shadow is aligned with the Y of object 3 (because that's how I keep it on the blocks of that height without the shadow jumping with the player), and I tried using basically the same commands as above, only I tried aligning it to a different object's Y-axis to try and draw the shadow on that platform. All I did was change from object position y(3)+2.5 to object position y(7)+6.5, but it did nothing.

Oh well, I've been at this all day...I suppose for now I could make my game so that all the platforms are on the same height, but I really wish I could do otherwise.

EDIT: Forgot to give y'all my entire drawing routine...


When I did one of my first forum searches yesterday, I came across a thread that mentioned 'the shadow in Lee's room example'. I remembered this from running the example programs in DarkBASIC, only I couldn't find it yesterday or today and I searched like mad. I don't know if that would help me, but does anybody know what example I'm talking about? Basically it's the one where you're a crab trapped, and you push this ball around in a room with running water and shadows. I don't know why I can't find it.



Check out my programming blog!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Mar 2009 02:48
So you didn't figure it out? I can't remember the name of that scorpion one. I'll look around. In the meantime, I'll sumarize quickly the get ground height post I had made and asked you to read through. The idea is, you create your environment - blocks, landscapes, etc. Set the collision of your environment to polygons, use a feeler object that you lower or raise until it collides with the environment, get the height of the feeler object as soon as it collides. Or do the same things using Sparky's collision DLL. This will return the height much more easily.

An alternative is to use the method that you are using. Put object collision boxes around the items you want to check for collision (your platforms, the sphere) and get the y position of the collision. The shadow is always positioned at the X and Z of the sphere. Below the sphere, have an invisible thin long box or plain with which to detect collision with anything underneath the sphere. This long feeler object will have a collision box made around it so it can return the y collision coordinate. Place the shadow at this collision Y.

That should do it. If the sphere jumps, the long feeler box should be between platforms and therefore drop down below which the shadow should follow. I'll knock together an example if I have some time.

Enjoy your day.
Yodaman Jer
User Banned
Posted: 14th Mar 2009 03:20
I follow your idea Latch, I just have a few prolbmes when implementing it. First, the 'feeler' won't jump with my sphere, it stays on the same y-unit the whole way through, so if I try and make the shadow appear on higher or lower platforms, it doesn't work.

The second problem is that the feeler isn't aligned with my sphere properly. It's offset by a unit or so. Instead of hiding the feeler object (which is just a long box)I just ghosted it so that I could see what it was doing. That's how I discovered that problem.

The third is that the shadow will only disappear 50% of the time over gaps, which is odd.

Here's my code, with your idea implemented...


It's an ingenious idea you have. I just wish I were smart enough to solve the little problems myself. Sometimes I feel like I'm abusing the use of the DBC boards.



Check out my programming blog!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Mar 2009 03:43
Here's your code with the idea implemented. I didn't do any shadow resizing. You can do that once you're comfortable with the approach. I commented out a few lines that were making things difficult from your original source. The shadow should only be moved based on the sphere position or the colision detection. For some reason, I can't get the Y collision value of the feeler to be different than .5 so I had to calculate the y height based on the object that the feeler collided with. That means


The +.1 moves the shadow up just a little more so it's visible.



Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 14th Mar 2009 03:51 Edited at: 14th Mar 2009 03:54
one solution i just thot of would be to use the same code i gave for positioning the shadow below u to position a really really thin and long cylinder below you. use ghost or hide object to hide the cylinder from view, then use the following to check wat object it is colliding with:



hope that works and make sure the cylinder is hidden
Yodaman Jer
User Banned
Posted: 14th Mar 2009 03:52
Thanks Latch! I ran that code, then added another platform that was 5 units higher than the other two, and when I ran it again the shadow moved itself up!

I really can't thank you enough. You really helped me out today man. Thanks. Here's a coffee!





Check out my programming blog!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Mar 2009 18:15
Hmm, I happen to be doing the same thing right now with one of my games, and when you zoom the camera out, the shadow plain starts to "melt" into the ground. More like the ground object is half drawing over the shadow plain in sections. Is there a way to fix this?

@ Yodaman Jer

If you want I could post the code for my shadow, but it works with 3D objects using sparky's DLL, and I don't know if you know how to work that yet... Let me know though.

TheComet

Peachy, and the Chaos of the Gems

Yodaman Jer
User Banned
Posted: 2nd Apr 2009 19:08
Sorry Comet, I haven't visited this thread in a while. I have never used Sparky's DLL, and to be perfectly honest with everybody, I'm thinking about switching from DarkBASIC to something different. Not because I don't like DarkBASIC, but because I think I've outgrown it.

Anyway, if you want to show the code for your shadow, I'm sure others would be interested as well. Shadows can be a bit of a pain, as this thread proved. Though, that may just be my inability to grasp a new idea quickly biting me in the butt. But I'm getting better at programming! Coffee helps...



Check out my programming blog!
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 2nd Apr 2009 21:56
But, but, but!

Quote: "I prefer DarkBASIC over Blitz3D"


You SAID that!

That's what they WANT you to think...
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 2nd Apr 2009 23:04
how dare you mock DB, HOW DARE YOU!!!!

whoops sorry got a little emotional there, neway y would u quit DB? Its a great language, u already know it, theres next to nothing u cant do with it (xcept maybe MMOs), ud have to learn a new language, and most of all... WE'D MISS YOU!!!! Whoops did it again, but seriously theres no reason to quit DB
Yodaman Jer
User Banned
Posted: 3rd Apr 2009 02:38
Ah yes, proven wrong by my own blog!

OK guys, let me tell you: DarkBASIC is wonderful, and without it I never would have learned how much fun programming can be. It helped me realize that making games not only requires smarts, but talent as well.

I will always love DarkBASIC, and will indeed still use it for small programs. But I need something more powerful that resembles C for the bigger plans I have, and Blitz3D does fit that category. XNA Studio could fit it to, now that I think about it...

Anyway, I wrote that blog post (the one that Quirkyjim quoted) rather hurriedly, before I really gave Blitz a good chance. About two days after I wrote that post, I started finding tutorials on Blitz code and found that I actually liked it more than I had thought at first. I realize this seems like I'm contradicting myself, but it's just a matter of opinion. I will always use DarkBASIC for small programs (I'm actually writing a tutorial for something...I'll post it in a few days), but I really have outgrown it, in the sense that I need something a bit more powerful that isn't DarkBASIC.

Quote: "how dare you mock DB, HOW DARE YOU!!!!"


I would never mock DarkBASIC!! It taught me the very basics of programming and helped me to realize my passion for computer science. In my mind, DarkBASIC is on a pedestal, surrounded by a sparkling, golden light sent from God Himself, with Angels flying in circular motions above it with a 'Hallelujah' chorus playing in the background. I ain't dissin' t3h powerz of da DarkBASIC!!

Quote: "WE'D MISS YOU!!!!"


Don't worry, I'm not leaving! I'm just going to start using a different tool. I will still be on here, occasionally helping out the new comer and possibly writing tutorials (stay tuned for that one I mentioned earlier!). I have just outgrown DB and want to start learning a different language. If I learn Blitz, I'm honestly *this* much closer to understanding things like C# and C++ (because its language is a hybrid of BASIC and C).

I promise I will never leave you guys...oh great, I'm gonna cry...*sniff*.

Aw, group hug!!




Sorry, got a bit emotional here.



Check out my programming blog!
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Apr 2009 04:34
our little yodaman is all grown up
how many more noobs am i going to see come through and leave before I move on?
i wonder how many latch and TDK have seen, what happened to TDK anyway?

can't read?
Yodaman Jer
User Banned
Posted: 3rd Apr 2009 06:30
I asked the same question awhile ago over in Geek Culture, OBese.

The only person who knew was either Van B or BatVink...he's fine, he's just not active on the forums right now. I do wonder why though...

That tutorial I mentioned earlier should be done either this weekend or sometime next week. It depends on whether or not I'm going to Wisconsin. And if I can get it done in time.

Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Apr 2009 07:51
what is the tutorial about?
"Yodaman's Uber Tutorial
step 1: buy dark basic classic.
step 2: put it in the bin and get blitz 3D!"

thats actually copied from his website yknow, the cheek!

can't read?
Yodaman Jer
User Banned
Posted: 3rd Apr 2009 20:39
Lol, OBese. No. My tutorial will be about light mapping your DBC level using no outside light mapping applications or using the built-in lights of DBC, although one or two are required to get the atmospheric look of your level.

I'm still typing up the loose ends, and I don't think I'll be able to have it done by this weekend. Probably later next week.

Login to post a reply

Server time is: 2025-08-08 20:42:39
Your offset time is: 2025-08-08 20:42:39