Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe
I still think you might have better luck with an octree than a binary tree. With a binary tree, each level down the tree you travel you can discard around half the elements as being invalid. With an octree, you can discard up to 7/8ths of them.

However, given what you've just tried I can't guarantee that that will help all that much. I can see three ways forwards for you here:

1) Analyze the poo poo out of the tree. Compare how many aabb->aabb checks the tree is doing per search compared to your baseline of 7,000. Try and figure out why the value is so high; maybe the tree is too top heavy due to lots of elements sitting on node dividers, maybe the tree isn't deep enough. Run the code through a profiler to try and see if there are any bottlenecks in the code, or if you're spending lots of time in unexpected places in it. Given the number of AABB intersections you're doing, you might have some luck just optimizing the code for that check somehow. It might help to try and visualize it somehow, so you write code that renders the search in slow motion, so you can see the shape of the nodes, and the elements that are in them, and maybe get some clue to what is slowing it down.

2) Try a different data structure. Could be an octree, but there may also be other algorithms which would be better suited to the kind of data set you're working with that I'm not familiar with.

3) Accept the fact that doing an Order N Squared operation on 14,000 items is going to be slow, and try and work around it somehow, so it's not an issue for the rest of the game as a whole. You could simplify the data set, or simply not do the check very often. You could try running the check on a separate background thread while the game is running, or try and split the operation up, so you only do a small proportion of it every frame update.

Gerblyn fucked around with this message at 21:40 on Jul 5, 2011

Adbot
ADBOT LOVES YOU

Vinlaen
Feb 19, 2008

Paniolo posted:

Use something like Stencyl, Game Maker, or Unity for prototyping.
Thanks... I've been fooling around with Stencyl but it doesn't seem to have any GUI/UI elements which is kinda strange. I know that Unity has them but I'm not sure about Game Maker...

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Hey I'm making an object management and serialization API, tell me if this sounds like a good idea:

- Garbage collected
- 4 types of data: Arrays, objects, strings, and structures. Strings and structures are always inlined in one of the other two. Objects are a collection of properties associated with a class. Arrays can be multidimensional. All objects are by reference, not by owner, so you can have circular or complex references. Numbers are a special type of structure.
- All global symbols are part of a namespace.
- The main serialization format is a "package", which is a collection of all objects in the namespace you associate with that package. Attempting to load a symbol in a namespace associated with a package will load the package.
- ... or you can just write out individual objects and it'll write them along with their dependencies.
- You can specify namespaces as immutable, which guarantees that all objects in that namespace are flagged as immutable. Immutable objects can only reference other immutable objects. Immutable objects are only serialized as references, unless they are from a namespace flagged as duplicatable.
- Normally, objects in other namespaces will be serialized as references, but if flagged as duplicatable, they are copied. If loaded multiple times, they are compared for conflicts. Can be used for fast-load caches or shared dynamically-generated data.
- You can specify classes as always inheriting their mutability settings from another namespace to further restrict mutability.
- You can set packages to reserialize automatically. This is designed to make config files easy. A separate store-out file will be maintained for that package, loading symbols in that package will try the store file first. If the package is collected by the garbage collector, it will automatically save to that file.

Oh yeah and this is also bolted on to a programming language that is more or less a C# ripoff except worse, but you don't really have to use that. The main gimmick of it is that attempting to modify an immutable object results in a runtime exception.

OneEightHundred fucked around with this message at 06:01 on Jul 6, 2011

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
OneEightHundred: One goofy edge case for serialization frameworks that's a classic is hash-based data structures. In many languages, objects have a default hashcode which is based on the address of the object in memory. This means that when you deserialize a hashmap, for example, you actually need to re-bucket elements since their hashcodes may be different. How do you handle this if the hashmap is meant to be immutable?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Internet Janitor posted:

OneEightHundred: One goofy edge case for serialization frameworks that's a classic is hash-based data structures. In many languages, objects have a default hashcode which is based on the address of the object in memory. This means that when you deserialize a hashmap, for example, you actually need to re-bucket elements since their hashcodes may be different. How do you handle this if the hashmap is meant to be immutable?
Immutable objects can be modified by the host (i.e. you can load a data resource and then have the host perform further processing on it as well), they just can't be modified by the runtime.

Something like a hashmap could be done by with an on-load trigger and not allowing code-defined hash code generation (i.e. assume structs are always POD types)

OneEightHundred fucked around with this message at 07:07 on Jul 6, 2011

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm halfway into doing some kind of component-based design for a little game engine, and here is where I am getting stuck and needing to make sure I even fundamentally understand what it means to use that kind of design. It's been easy enough when I was working with graphics, physics, and audio generally, but when it comes down to specifically controlling entities, it all becomes a mess in my head. This is because now I'm dealing with different subsystems that could actively compete for the entity's attention and influence it in different ways.

For the sake of discussion, imagine an entity that could be controlled in a few different ways. I am going to list a ton of ways--some of which I personally might not use. However, I think the more the merrier in trying to understand how to organize all this stuff:
1. Player is controlling it directly.
2. AI is controlling it.
3. Maybe a scripting engine is making it do some acting stuff for cutscene crap.
4. Somebody remotely is controlling it--network is managing it.
5. Maybe it's in demo mode and is playing back a sequence of events.

So right now I have a subsystem for controllers and am working on one for AI and basic scripted events. But without knowing any better I'm not sure how to arbitrate the different methods of control. I thought the original idea would be for all three, I'd have a subsystem with its own callbacks. The callbacks would state what to do next with the entity. I guess then the entity would need to know which one it's actively being controlled by, and ignore stuff from everybody else.

If I'm ignoring the other callbacks, I wondered instead that most all these could go through some common callback, and the entity or something else would tell all the other subsystems to stop calling back.

Since this is pretty messy, you can ignore the lot of this and just talk about how you'd approach multiple avenues of controlling an entity. That would probably be a good start.

TheresaJayne
Jul 1, 2011
I am working on a fairly large project, but I am new to game development having worked mainly with server side stuff,

I have large data sets, objects x y z coord facing etc.

how do i convert it to a 3D view, Java3D or C++

project is at https://www.sf.net/projects/tranq-online

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Rocko Bonaparte posted:

I guess then the entity would need to know which one it's actively being controlled by, and ignore stuff from everybody else.
Can you give an example of this? Maybe I'm not understanding your system correctly, but why would an entity need knowledge about it's controller? I would think you'd design an API around the commands an entity can receive regardless of where they're coming from.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Orzo posted:

Can you give an example of this? Maybe I'm not understanding your system correctly, but why would an entity need knowledge about it's controller? I would think you'd design an API around the commands an entity can receive regardless of where they're coming from.
I had thought about doing something like that as part of my big ramble. But the impression I had gotten was if an entity "supports" a subsystem, then it implements some interface for it. I am supposing that things like control and AI could technically just implement the same interface. If that's the case I'm trying to figure out what decides when and where how to turn on/off different subsystems sending stuff through the interface.

I think an good example of this is something like an action RPG where playable characters cross a trigger point that starts a small dramatization. At that point the computer is moving stuff around for the player and the controllers shouldn't be moving the characters anymore. Then when that's done they can take back control. Alternately, I was thinking if there is 1 person and 2 characters, maybe they'd want to switch between them. That would mean switching between manual control and an AI for both of them.

dangerz
Jan 12, 2005

when i move you move, just like that
I'm having a weird texture issue in XNA. Here's a screenshot to help explain:



I generate the terrain below it and put it in a Vertex Buffers to be pushed to the GPU (each chunk has it's own VB). Then I create another vertex buffer for the 'ocean' above it (which ends up being a plane with a transparent texture applied).

The issue I'm getting is that sometimes the plane is transparent and you can see what's underneath it (look at the top left of the picture for an example of when it works) and sometimes it's opaque (like where the circle in the middle is). I can't seem to figure out why it's doing this. The texture is a PNG with 80% transparency. I tried to make the texture have 100% transparency in spots but that has the same issue. I'm using the BasicEffect shader (I haven't learned HLSL yet).

I think this is a Vertex Buffer/Transparency issue only because if I import a square model, give it a transparency and just instantiate it thousands of times to simulate what I have here I have no issues besides the fact that my game runs extremely f'n slow. Anyone have any tips?

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Rocko Bonaparte posted:

I had thought about doing something like that as part of my big ramble. But the impression I had gotten was if an entity "supports" a subsystem, then it implements some interface for it. I am supposing that things like control and AI could technically just implement the same interface. If that's the case I'm trying to figure out what decides when and where how to turn on/off different subsystems sending stuff through the interface.

I think an good example of this is something like an action RPG where playable characters cross a trigger point that starts a small dramatization. At that point the computer is moving stuff around for the player and the controllers shouldn't be moving the characters anymore. Then when that's done they can take back control. Alternately, I was thinking if there is 1 person and 2 characters, maybe they'd want to switch between them. That would mean switching between manual control and an AI for both of them.
What I was getting at is that your entities (let's say, characters) should have a contract and shouldn't care about who is making the calls to it. Take for a simple example an RPG character that can move in 4 directions and slash its sword. The default state of your game is to have an input processor which controls the character. When you press up, the character is given an 'up' command. It doesn't know or care that the up command came from the keyboard.

Now let's say you hit a trigger and the game goes into cutscene mode. This should effectively change your game loop so that the input processor is no longer passing through controls to the character; instead, you're (for example) reading a cutscene script file and applying the actions to the character in sequence. The character class does not know it is being controlled by a cutscene, just that it's being told to move left, then up, then slash its sword, then move right.

Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe

Rocko Bonaparte posted:

I had thought about doing something like that as part of my big ramble. But the impression I had gotten was if an entity "supports" a subsystem, then it implements some interface for it. I am supposing that things like control and AI could technically just implement the same interface. If that's the case I'm trying to figure out what decides when and where how to turn on/off different subsystems sending stuff through the interface.

I think an good example of this is something like an action RPG where playable characters cross a trigger point that starts a small dramatization. At that point the computer is moving stuff around for the player and the controllers shouldn't be moving the characters anymore. Then when that's done they can take back control. Alternately, I was thinking if there is 1 person and 2 characters, maybe they'd want to switch between them. That would mean switching between manual control and an AI for both of them.

I made a post about a possible solution for this a few pages back:

http://forums.somethingawful.com/showthread.php?threadid=2692947&pagenumber=84&perpage=40#post390228673

Where characters are controlled by sending them messages. The character's themselves don't need to know where the messages are coming from, allowing a higher level system like a cutscene manager or a player controller decide what gets to route which messages to which characters.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

dangerz posted:

The issue I'm getting is that sometimes the plane is transparent and you can see what's underneath it (look at the top left of the picture for an example of when it works) and sometimes it's opaque (like where the circle in the middle is).
You probably have depth write enabled. If that's the case, it'll appear translucent if it's drawn after the geometry below it, but opaque if it's drawn before because it'll block anything behind it from being drawn.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

OneEightHundred posted:

You probably have depth write enabled. If that's the case, it'll appear translucent if it's drawn after the geometry below it, but opaque if it's drawn before because it'll block anything behind it from being drawn.
... for which the solution is to draw all your transparent things last, and, if there's more than one transparent thing that might overlap, draw them in order from far to near.

dangerz
Jan 12, 2005

when i move you move, just like that

OneEightHundred posted:

You probably have depth write enabled. If that's the case, it'll appear translucent if it's drawn after the geometry below it, but opaque if it's drawn before because it'll block anything behind it from being drawn.

roomforthetuna posted:

... for which the solution is to draw all your transparent things last, and, if there's more than one transparent thing that might overlap, draw them in order from far to near.
Ah ok, thank you very much. I'll try this tonight.

edit: Awesome, that fix worked. Thank you very much :]

dangerz fucked around with this message at 22:41 on Jul 6, 2011

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
One other thing to be aware of is that using XNA's spriteBatch class will change both the depth buffer and alpha blend states when you call spriteBatch.Begin(), but calling spriteBatch.End() does not restore the original state. This can call all sorts of funkyness when you're mixing 3D and spriteFont draw calls like you appear to be doing in your screenshot.

The simple test is to comment out your spriteBatch calls and see if the image changes, then if it does you need to manually store/restore the depth and alpha blend settings before/after drawing your 2D HUD elements.

dangerz
Jan 12, 2005

when i move you move, just like that

PDP-1 posted:

One other thing to be aware of is that using XNA's spriteBatch class will change both the depth buffer and alpha blend states when you call spriteBatch.Begin(), but calling spriteBatch.End() does not restore the original state. This can call all sorts of funkyness when you're mixing 3D and spriteFont draw calls like you appear to be doing in your screenshot.

The simple test is to comment out your spriteBatch calls and see if the image changes, then if it does you need to manually store/restore the depth and alpha blend settings before/after drawing your 2D HUD elements.
Ya I came upon that issue a while ago and solved it by resetting everything on each pass. I don't know if there's a more efficient way to do it but it works.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
http://blog.spacestro.com/

There. You guys have convinced me to do it. We just hit milestone 2 which was too god drat long and we didn't feel like refactoring at the end. :saddowns:

However, for milestone 3, we're just going to implement a small amount of features so we're not bogged down with too much and still have the mental fortitude to clean up code. Here, have a screenshot.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Gerblyn posted:

I made a post about a possible solution for this a few pages back:

http://forums.somethingawful.com/showthread.php?threadid=2692947&pagenumber=84&perpage=40#post390228673

Where characters are controlled by sending them messages. The character's themselves don't need to know where the messages are coming from, allowing a higher level system like a cutscene manager or a player controller decide what gets to route which messages to which characters.
Basically a command pattern? I'll end up giving something like this a go. It was one of the things on the table anyways. It's been two days since I really had my face glued to the code so I've had enough time to step back and not freak out about anything so much.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Cross-posting this:

http://forums.somethingawful.com/showthread.php?threadid=3423863

Rutibex
Sep 9, 2001

by Fluffdaddy
Edit: I no longer need any help :ninja:

I am in need of some programming help I and think this is the thread to ask about it. I make Minecraft adventure maps and have recently branched into Terraria but I have a bit of a hitch. Someone has made a very exellent map editor but the touchy Terraria devs have told him to strip out the chest copy/paste/content editing feature to prevent "cheating" (lol).

I emailed the dev and asked him if he could give me a binary with the editing on the sly and he told me that he couldn't but gave me some instructions on how I could do it myself. The editor is open source and apparently the chest editing code exists in versions july 7th or earlier but is "commented out" as part of the pointer tool. He said I just needed to fix that in the earlier version and compile it using visual c# express edition.

The extent of my programming abilities ends with RPG Maker so I'm asking for some help. Could someone uncomment the code and provide me a binary that I can use? If you could some how port the feature to the latest version that would be even better but I'm not greedy, I can work with the older one. The Terraria thread needs you!

https://github.com/BinaryConstruct/Terraria-Map-Editor/

Rutibex fucked around with this message at 00:43 on Jul 10, 2011

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
In the wee hours of the morning today I wrote a Sokoban game in Forth:


Here's the source: https://github.com/JohnEarnest/Mako/blob/master/examples/Sokoban/Sokoban.fs

I may still add some features like a step counter, nicer level transitions and more levels, but it's basically all there.

Internet Janitor fucked around with this message at 17:31 on Jul 9, 2011

Nalin
Sep 29, 2007

Hair Elf

Rutibex posted:

Could someone uncomment the code and provide me a binary that I can use? If you could some how port the feature to the latest version that would be even better but I'm not greedy, I can work with the older one. The Terraria thread needs you!
Done. I PM'ed you a link. I didn't merge it with the latest changes because, from what I could see, there wasn't much changed. But I am not used to git at all so what do I know?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I've got more conceptual problems with component-based design, based on an accumulation of factors. My issue now is with information sharing for an AI subsystem. I want the AI to take care of an entity for me to have it approach the player and start attacking it. The big question in a design situation for me is how the AI should figure out who the players are and where the players are. Some approaches that aren't incompatible:

1. Just tell the AI sub system up front into hard-coded slots. This is what I'm doing right now while I figure out what the hell I'm doing. I can smash away on a lot of stuff and refactor it later. So I'm not entirely stuck or anything.
2. Some sort of "faction" system with entities so that entities of incompatible factions naturally try to duke it out. But then my entities would have to have some awareness of this. I guess that could be a required interface method when registering with AI.
3. Maintaining a list of all entities and scanning against that. Something like faction information would have to be a part of that so that each entity knows how to respond. Generally the search system on that scares me. It also sounds a lot like putting too much on entities, to the point of tempting to subclass them.

Anyways I have something at hand right now while I settle on something but I wanted again to vet my problems with people more experienced with this whole setup.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Rocko: You can always do mixins. Say you make that "team" attribute part of its own iterface like so:

code:
public interface Factional {
    public int team();
}
Then have some of your entities implement it. When you're figuring out what belongs to a given team, use your equivalent of instanceof to identify 'factional' entities. For every mixin interface, your engine just has to guard with a type check and have some sort of sane default for things that don't implement the interface. (Do 'non-factional' entities belong to no team, or an implicit 'neutral' team, etc.)

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Internet Janitor posted:

Then have some of your entities implement it. When you're figuring out what belongs to a given team, use your equivalent of instanceof to identify 'factional' entities.
Actually maybe I'll latch on to that for a moment, and maybe it's a question for the C++ thread. They make a huge fuss over casting in C++. There is a way to determine the types of stuff dynamically, but it requires an extra compilation option and "performance will go down." I haven't seen it quantified so I wondered the type name stuff in C++ really is a burden. It has hampered my thinking when trying to resolve some of this stuff.

Paniolo
Oct 9, 2007

Heads will roll.
Rocko the problem with your question is that there are a million and one possible answers and although some of them would be blatantly bad, there's absolutely no "one true way." What you're getting at isn't anything specific to a component-based game engine, or game programming at all, but some pretty fundamental OOP issues.

As you've surmised RTTI is one tool that can simplify implementing this kind of system, but it does have a performance cost. I'd caution you against worrying too much about it, though - on a PC platform the performance cost of enabling RTTI and exceptions is essentially negligible, and the benefits are tangible. (On an embedded system the analysis changes sharply.)

A very simple way of querying for components is for each component implementation to register itself under a specific name, which can be a string or a unique integer or whatever you want it to be. Then you have code which looks like this:

code:
IFactionUnit* factionUnit = static_cast<IFactionUnit*>(entity->GetComponentByName("IFactionUnit"));
if (factionUnit) {
   // Do something.
}

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
I'm taking part in the 1 month SA game dev compo, and I'm running into a bug I can't seem to figure out how to fix. For reference, I'm writing this code in Flixel (AS3).

One of my characters floats in water, which I accomplished by giving him an upward acceleration when he was flagged 'wet' (ie, contacting water tiles). Once he is dry, he gets a normal downward acceleration. What I expected would happen is that he would shoot up to the surface and float on top of it. What's actually happening is that he behaves like a spring that is getting more and more energy. At first he bobs up and down a little, but with every bob he goes wilder and wilder. Pretty soon he's flying in and out of the water.

Any suggestions on fixing this? It seems like it's probably a common game development problem.

tl;dr: Character in water bobs up and down out of the surface faster and faster and faster. I want him to come to rest on the surface.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Paniolo posted:

Rocko the problem with your question is that there are a million and one possible answers and although some of them would be blatantly bad, there's absolutely no "one true way." What you're getting at isn't anything specific to a component-based game engine, or game programming at all, but some pretty fundamental OOP issues.

As you've surmised RTTI is one tool that can simplify implementing this kind of system, but it does have a performance cost. I'd caution you against worrying too much about it, though - on a PC platform the performance cost of enabling RTTI and exceptions is essentially negligible, and the benefits are tangible. (On an embedded system the analysis changes sharply.)

A very simple way of querying for components is for each component implementation to register itself under a specific name, which can be a string or a unique integer or whatever you want it to be. Then you have code which looks like this:

code:
IFactionUnit* factionUnit = static_cast<IFactionUnit*>(entity->GetComponentByName("IFactionUnit"));
if (factionUnit) {
   // Do something.
}

Yeah this is what I do for my componentized entity system and user interface system where I register each class implementation with a unique key (in my case, a simple string hash of the class name) and then I can determine what kind of class a particular entity component/interface is. It works great and really doesn't need any crazy RTTI stuff, like typeid or what-have-you. Everything is done with #define macros so it's easy to implement. It kinda looks like MFC where you define your controls/attributes and what events they respond to.

Pfhreak: You should reduce the acceleration by some sort of dampening value on every up-down movement, where it eventually goes to zero. After every up-down, make the acceleration a fraction of what it was before.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Pfhreak posted:

tl;dr: Character in water bobs up and down out of the surface faster and faster and faster. I want him to come to rest on the surface.

The first thing I'd look at is the notion of 'giving him an upward acceleration when he was flagged wet'. I might be reading too much into your comment but you shouldn't be applying an acceleration, you should be applying a force. The character will always feel the downward force of gravity and if he's wet he'll also feel an upward force of buoyancy. The acceleration is something that pops out of F=ma, not something you set explicitly.

The second thing to look at is whether a stable solution exists for a character that is flagged as 100% wet or dry in a binary way. If the character is wet he'll experience a net upward force, and if he's dry he'll experience a net downward force, so if the situation is one where the character is only wet/dry he'll always be accelerating up or down with the direction flipping positive/negative and won't come to rest. What you might need to do is perform your wet/dry test and if the character is touching water you'd figure out what percentage of their hitbox is 'wet' and apply that fraction of the 100% wet buoyant force. A binary up/down force won't have a stable solution, but a more analog wet/partly wet/dry situation should be able to come to a point where the upward and downward forces cancel.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

PDP-1 posted:

The first thing I'd look at is the notion of 'giving him an upward acceleration when he was flagged wet'. I might be reading too much into your comment but you shouldn't be applying an acceleration, you should be applying a force. The character will always feel the downward force of gravity and if he's wet he'll also feel an upward force of buoyancy. The acceleration is something that pops out of F=ma, not something you set explicitly.

The second thing to look at is whether a stable solution exists for a character that is flagged as 100% wet or dry in a binary way. If the character is wet he'll experience a net upward force, and if he's dry he'll experience a net downward force, so if the situation is one where the character is only wet/dry he'll always be accelerating up or down with the direction flipping positive/negative and won't come to rest. What you might need to do is perform your wet/dry test and if the character is touching water you'd figure out what percentage of their hitbox is 'wet' and apply that fraction of the 100% wet buoyant force. A binary up/down force won't have a stable solution, but a more analog wet/partly wet/dry situation should be able to come to a point where the upward and downward forces cancel.

Interesting. Flixel doesn't expose the force (as far as I can tell). And in this case, my objects are all 1 mass, so F = A. I was worried I'd have to figure out the % of the hitbox covered. I'm not looking for a perfect solution, it just has to be 'good enough' -- one month game dev competition and all. :D

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Pfhreak posted:

tl;dr: Character in water bobs up and down out of the surface faster and faster and faster. I want him to come to rest on the surface.
The reason this doesn't happen in the real world is because buoyancy is relative to how much of the object is submerged. A partially-submerged object is not as affected by buoyancy as a totally-submerged one, which means a smoother transition of force at the surface. If you don't want to handle partial submersion, then you can add a "surface tension" mechanism of some sort which causes objects to lose energy if they cross a water boundary.

The other thing you can do is apply friction from the water viscosity.

As for characters, a person will just sink if they do nothing in water, players not providing input don't want to sink, they want to swim so that they stay in the same place. Apply additional friction to account for that "correction."

OneEightHundred fucked around with this message at 16:48 on Jul 11, 2011

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Pfhreak posted:

Interesting. Flixel doesn't expose the force (as far as I can tell). And in this case, my objects are all 1 mass, so F = A. I was worried I'd have to figure out the % of the hitbox covered. I'm not looking for a perfect solution, it just has to be 'good enough' -- one month game dev competition and all. :D

Huh, I suppose that is a special case of F=mA if everything has unit mass. Cool.

You might be able to get around explicitly finding the % of the hitbox that is wet if you just do your wet/dry test on a point near the character's feet and a second point near their head. If the head is dry and the feet are wet the character is spanning the edge of a water tile and you'd apply a weighted mix of both gravity and buoyant forces where the weighting factors come from how far the head/feet are from the horizontal top of the water tile, respectively. That way a character transitioning from 100% wet to 100% dry would experience a smooth transition in the applied force and could actually come to a stable solution where gravity = buoyancy.

dereekb
Nov 7, 2010

What do you mean "error"?
Hey, quick question for you guys:

What is the best way to create a seemingly infinite flat plain? Is it best to create a mesh that is really big and moves relative to the player, or to create a quad that has corners that go from "-Infinite" to "Infinite"?

I'm guessing the mesh/model option.

And if you're wondering why, its for a water plain.



To Pfhreak:

A simple way to "remedy" your problem with less of a physics approach, depending on what you have to work with (like a static water level), is capping his movement speed at water level, if you can do that.

This won't work if it is noticeable though, like if your character falls 1000 or so feet into a lake and suddenly he is going the maximum speed set...

dereekb fucked around with this message at 16:50 on Jul 11, 2011

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

dereekb posted:

What is the best way to create a seemingly infinite flat plain?
The main artifact you're fighting is the horizon "moving" by being a variable distance from the player.

If it's a completely contiguous plane (i.e. no holes in the middle of it), then just move a mesh with the player.


If you're dealing with a non-contiguous one, mark edges of meshes as extending infinitely. When rendering, add additional polygons that go from points of those edges to the near or far plane. Make sure that if one edge extends to the near plane and the other to the far plane, you properly contour the view frustum.

dereekb
Nov 7, 2010

What do you mean "error"?

OneEightHundred posted:

The main artifact you're fighting is the horizon "moving" by being a variable distance from the player.

If it's a completely contiguous plane (i.e. no holes in the middle of it), then just move a mesh with the player.


If you're dealing with a non-contiguous one, mark edges of meshes as extending infinitely. When rendering, add additional polygons that go from points of those edges to the near or far plane. Make sure that if one edge extends to the near plane and the other to the far plane, you properly contour the view frustum.

Alright, then I'll be using the mesh.

Its going to be contiguous since it will act as the "ocean". To fight it from looking weird going outside loaded chunks, I'll have the effect fog off into the distance or something like that.

Paolomania
Apr 26, 2006

By moving a mesh with the player I think OEH means keep the mesh fixed with respect to player coordinates, and translate the texture when the player moves to give the illusion that the mesh is moving.

dereekb
Nov 7, 2010

What do you mean "error"?

Paolomania posted:

By moving a mesh with the player I think OEH means keep the mesh fixed with respect to player coordinates, and translate the texture when the player moves to give the illusion that the mesh is moving.

I'm pretty sure that's what I interpreted it as. The mesh is moving with the player's camera.

With respect to what I'm doing, I'm not following you with "translate the texture" part. The texture should stay where it is, or how it normally operates?

Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe

dereekb posted:

I'm pretty sure that's what I interpreted it as. The mesh is moving with the player's camera.

With respect to what I'm doing, I'm not following you with "translate the texture" part. The texture should stay where it is, or how it normally operates?

To simulate the player moving over the mesh, you translate the texture on the surface under the player in the opposite direction the player is moving. So, if the player moves 1 meter forwards, you move the texture under the player 1 meter back, so it looks to the player as if the mesh is moving beneath him, rather than actually being attached to him.

Adbot
ADBOT LOVES YOU

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Pfhreak posted:

Interesting. Flixel doesn't expose the force (as far as I can tell). And in this case, my objects are all 1 mass, so F = A. I was worried I'd have to figure out the % of the hitbox covered. I'm not looking for a perfect solution, it just has to be 'good enough' -- one month game dev competition and all. :D

You should really add a drag force - it will not only help (maybe even fix) your problem, it would be more realistic too.

A drag force should be proportional to the objects speed through the water and in the opposite direction. Fiddle with the proportionality constant until you get something that works.

Edit: you need to combine this with the partially submerged force someone mentioned earlier. Here's a little demo, save it as an .html and open in a browser to watch. Compare with turning the drag off, where it goes on forever.

code:
<html>
<body>
<canvas id="canvas" width="300" height="300">test</canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var canvasContext = canvas.getContext("2d");

timer();
var y = 100;
var speed = 0;

function timer() {
	var t = setTimeout(function() {timer();}, 15);
	var a;
	//Water level is at 150, ball is 30 pixels in diameter
	if(y > 165){                            //In the water:
		a = -.6;                        //Bouyant
		a += -speed * .05;              //drag
	}else if(y <= 165 && y > 135){          //Somewhat submerged
		var submerged = (y - 135) / 30; //Proportion submerged
		a = 1 - (1.6) * submerged;      //Gravity - bouyancy
		a += -speed * .05 * submerged ; //drag
	}else{                                  //Completely submerged
		a = 1;                          //Gravity
	}

	speed += a;
	y += speed;

	//Draw background
	canvasContext.fillStyle = "rgb(0,255,255)";
	canvasContext.fillRect (0, 0, 300, 150);
	canvasContext.fillStyle = "rgb(0,0,255)";
	canvasContext.fillRect (0, 150, 300, 150);

	//Draw ball
	canvasContext.fillStyle = "rgb(255,0,0)";
	canvasContext.beginPath();
	canvasContext.arc(150, y, 15, 0, 2 * Math.PI, false);
	canvasContext.fill();
}
</script>
</body>
</html> 

HappyHippo fucked around with this message at 02:09 on Jul 12, 2011

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply