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
ZombieApostate
Mar 13, 2011
Sorry, I didn't read your post.

I'm too busy replying to what I wish you said

:allears:
I must say the minelayer is pretty drat fun :v:

I'm really curious to see how hectic this would get with more people.

Adbot
ADBOT LOVES YOU

Ranzear
Jul 25, 2013

ZombieApostate posted:

I'm really curious to see how hectic this would get with more people.

Goddamn, as am I.

It can scale to 16 teams, but would need more than 225 players to spawn the last one. I could dial this back to less than 1:1 players per team to teams.

It can cut back the tickrate (it's probably too high to start with, as good as my forward-sim is.) to reduce load enough to maybe handle that after some good optimization passes.

It might need some final objective to 'win', like 10k energy or something. Tank costs include 4% of your team's total energy and half of that is lost.

You can steal 20% of a team's energy (once a minute) by getting close enough to their base (almost touching) and deposit energy in your own base just the same.

Tank and module costs might need to be leveled out a tiny bit, since all that energy is dropped when you die.

DStecks
Feb 6, 2012

I am massively stuck on trying to code a grid-based Line of Sight system for my TRPG.

The way I'm handling it is that line of sight is based on tile objects which are created every time an enemy object moves tiles:



So far, so good. Every time the enemy begins to move, the LOS cone is cleared, using this code:

code:
public void clearVision()
    {
            int countSize = visionField.Count;
            for (int i = 0; i < countSize; ++i)
            {
                if (visionField[i].gameObject != null)
                {
                    GameObject destroyme = visionField[i].gameObject;

                    GameObject.Destroy(destroyme);
                    visionField.Remove(visionField[i]);
                }
            }
        
    }
Which, so far as I can tell, legitimately works.

So here's my problem:


The problem appears to be that this code here:

code:
void Start () {
        
        if (Pathfinding.objectAtCoordsWithTag(mapX() + offsetX, mapY() + offsetY, "noLOS") == false)
        {
            newBlock(offsetX, offsetY, RayBeamBlock);
        }
        
        if(isRayStart)
        {
            if(offsetX != 0)
            {
                if (Pathfinding.objectAtCoordsWithTag(mapX() + offsetX, mapY() + 1, "LOSblock") == false && Pathfinding.objectAtCoordsWithTag(mapX() + offsetX, mapY() + 1, "noLOS") == false)
                {
                    newBlock(offsetX, 1, RayStartBlock);
                }

                if (Pathfinding.objectAtCoordsWithTag(mapX() + offsetX, mapY() - 1, "LOSblock") == false && Pathfinding.objectAtCoordsWithTag(mapX() + offsetX, mapY() - 1, "noLOS") == false)
                {
                    newBlock(offsetX, -1, RayStartBlock);
                }

            }
            if (offsetY != 0)
            {
                if (Pathfinding.objectAtCoordsWithTag(mapX() + 1, mapY() + offsetY, "LOSblock") == false && Pathfinding.objectAtCoordsWithTag(mapX() + 1, mapY() + offsetY, "noLOS") == false)
                {
                    newBlock(1, offsetY, RayStartBlock);
                }

                if (Pathfinding.objectAtCoordsWithTag(mapX() - 1, mapY() + offsetY, "LOSblock") == false && Pathfinding.objectAtCoordsWithTag(mapX() - 1, mapY() + offsetY, "noLOS") == false)
                {
                    newBlock(-1, offsetY, RayStartBlock);
                }

            }
        }
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    private void newBlock (int offX, int offY, GameObject o)
    {
        GameObject newRay = (GameObject)Pathfinding.instantiateAtCoordinates(o, new MapXY(mapX() + offX, mapY() + offY));
        newRay.GetComponent<MapXY>().X = mapX() + offX;
        newRay.GetComponent<MapXY>().Y = mapY() + offY;
        newRay.GetComponent<LOSblock>().offsetX = offsetX;
        newRay.GetComponent<LOSblock>().offsetY = offsetY;
        newRay.GetComponent<LOSblock>().parent = parent;

        //Add the new LOSblock to the parent List of LOSblocks.
        parent.gameObject.GetComponent<LineOfSight>().visionField.Add(newRay.GetComponent<LOSblock>());
    }
Is detecting phantom LOSblocks where none should exist. It's only getting them on every other step, so am I maybe not destroying them properly? It only seems to happen when the offset is equal to -1, also. Here's "Pathfinding.objectAtCoordsWithTag()":

code:
public static bool objectAtCoordsWithTag(int x, int y, string tag)
    {
        Collider[] foundObjects = Physics.OverlapSphere(GameObject.Find("GameController").GetComponent<EncounterController>().LevelMap.contents[x, y].transform.position, 0.1F);

        for (int i = 0; i < foundObjects.Length; ++i)
        {
            if (foundObjects[i].GetComponent<HGtags>().hasTag(tag))
            {
                if(tag == "LOSblock")
                {
                    Debug.Log("PATHFINDING: LOSblock found at [" + x + "," + y + "]. Object is " + foundObjects[i].name);
                }
                return true;
            }
        }

        return false;
    }
I know this is a massive bunch of code for anyone to look at, but I've been digging at this for two days now and am not any closer to a solution.

EDIT: Made code less lovely, executes identically.

EDIT EDIT: Okay, I should be clearer, the clearVision code is not running perfectly. It appears to be correctly deleting all the objects, but it does throw "Argument out of range" errors because I can't find a way to iterate through the List while destroying each object without throwing these errors. At this point I feel like the problem is probably in an area where I don't totally understand how Unity does things.

EDIT EDIT EDIT: OK son of a bitch I am now 3 for 3 for finding the solution to a problem immediately after asking you guys. The problem was in clearVision after all. Here's the corrected code:

code:
public void clearVision()
    {
        int countSize = visionField.Count;
        for (int i = 0; i < countSize; ++i)
            {
            //if (visionField[i].gameObject != null)
            if (visionField[i] != null)
            {
                //GameObject destroyme = visionField[i].gameObject;
                GameObject destroyme = visionField[i];
                GameObject.Destroy(destroyme);
            }
        }

        visionField.Clear();
    }

DStecks fucked around with this message at 16:08 on Oct 8, 2015

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

DStecks posted:

EDIT EDIT: Okay, I should be clearer, the clearVision code is not running perfectly. It appears to be correctly deleting all the objects, but it does throw "Argument out of range" errors because I can't find a way to iterate through the List while destroying each object without throwing these errors. At this point I feel like the problem is probably in an area where I don't totally understand how Unity does things.

When you remove an element from the list, you need to subtract 1 from the index and also update the countSize to avoid going out of bounds.

You can also approach it other ways, such as going through the list backwards.

code:
for (int i = visionField.Count - 1; i >= 0; i--)
{
   
}

DStecks
Feb 6, 2012

It isn't throwing errors at all anymore, since I just Clear the whole list once I'm done with it. And there's never a scenario where I'd want to stop halfway through, so I think the code is probably OK as it is.

ChickenWing
Jul 22, 2010

:v:

DStecks posted:


EDIT EDIT EDIT: OK son of a bitch I am now 3 for 3 for finding the solution to a problem immediately after asking you guys. The problem was in clearVision after all. Here's the corrected code:


Welcome to my life. 25% of my problems are unsolveable on my own, but become bafflingly transparent as soon as I talk to someone else about them. Can't talk to myself though, that doesn't count

Fano
Oct 20, 2010

ChickenWing posted:

Welcome to my life. 25% of my problems are unsolveable on my own, but become bafflingly transparent as soon as I talk to someone else about them. Can't talk to myself though, that doesn't count

https://en.wikipedia.org/wiki/Rubber_duck_debugging

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
What's a good foundational basis for lighting in a tile-based 3d world? I'm starting to think about it for my situation since I'm reaching a point where I could actually worry about it. I asked about it earlier and saw some stuff about generating light information, but I have to admit I don't even know what I should be trying to do. At this point I assume that--given my map data is basically a 3d array--I should create a 3d texture representing my light levels at each location. I assume I then ingest that data into a shader. The lights I add affect that 3d texture and I apply all my logic for deciding how much an area of a level is affected by lights to that texture. Is this about right?

Ranzear
Jul 25, 2013

ZombieApostate posted:

I still got stuck where I couldn't shoot anymore with the LC and I think you saw what happened when ramming :v:

Maybe the shooting problem has something to do with trying to shoot before the recharge is finished?

You were right. I wasn't resetting burst to maximum when I set the cooldown.

Letting off the fire button with a partial burst was causing it to continuously reset the cooldown to the 'adjusted' amount, and then you had to hold the fire button down for that length of time for it to fire again and empty the burst, else it would keep resetting it.

Missiles, Mines, and Energy sprited. Tomorrow might be sound.

Ranzear fucked around with this message at 09:10 on Oct 9, 2015

DStecks
Feb 6, 2012

And now I've got an awesome new problem that fails for no good reason.

So, in my game, I'm using a class to hold tags for in-game objects (to specify if they're a map tile or if they block line of sight, for example). And my code that constructs an A* navigation map from the map tiles checks these tags when doing an OverlapSphere so that I don't get silliness going on. I'm now at the point in development where I need to move forward to a more advanced prototype, so I've created a new scene. The OverlapSphere is being created in the correct position, and is finding the tiles, but for some reason they don't have the assigned tags from the prefab, even though it shows that they do in the inspector:





"NOGOUpperFarLeft" is a tile I copied-and-pasted from the first, working, TEST scene. TestTileNOGOPrefab (50) is obviously created from a prefab. Notice their identical tags in the inspector.


EDIT: Four for four. The code that loaded those inspector tags into the actual data values wasn't running before the map was being built.

DStecks fucked around with this message at 17:12 on Oct 9, 2015

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Rocko Bonaparte posted:

What's a good foundational basis for lighting in a tile-based 3d world? I'm starting to think about it for my situation since I'm reaching a point where I could actually worry about it. I asked about it earlier and saw some stuff about generating light information, but I have to admit I don't even know what I should be trying to do. At this point I assume that--given my map data is basically a 3d array--I should create a 3d texture representing my light levels at each location. I assume I then ingest that data into a shader. The lights I add affect that 3d texture and I apply all my logic for deciding how much an area of a level is affected by lights to that texture. Is this about right?

Or do I just use built-in lighting with Unity and not freak out over this stuff?

Jewel
May 2, 2009

Rocko Bonaparte posted:

Or do I just use built-in lighting with Unity and not freak out over this stuff?

HitboxTeam, the devs behind Spire (previously DustForce) have been pretty much completely re-writing Unity's lighting. Here's some posts about it. Sorry there's not much more info but there's a lot to explain and a lot I don't personally know the details of.



http://hitboxteam.tumblr.com/post/118169134856/lighting-volumes-generated-at-run-time-still

http://hitboxteam.tumblr.com/post/121955642786/finally-plugged-the-baked-volumetric-light-volumes

http://hitboxteam.tumblr.com/post/128373526536/had-an-idea-for-a-hybrid-dynamicbaked-shadow

From what I remember, the last one there is basically trading memory for speed. Unity re-calculates lights per frame so it doesn't have to store them. Their approach is just creating a cubic lightmap for each light (or singular texture for a spotlight, etc) and recalculating if something or the light itself, moves within the region it effects. The speedup is enormous but it's not always necessary or feasible.

Their game also uses tile-based lighting as you can see in the top image, or at least, used to. Something like that would require mapping each tile to a 3D lightmap (where each "cell" in the 3D array is a single tile wide) and optimising so you only store detail about cells that actually are filled and etc. There's lots of different ways you can choose to light things, or just say gently caress it and use Unity's default one. If it works for you then it doesn't matter!

Jewel fucked around with this message at 18:24 on Oct 9, 2015

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Jewel posted:

Their game also uses tile-based lighting as you can see in the top image, or at least, used to. Something like that would require mapping each tile to a 3D lightmap (where each "cell" in the 3D array is a single tile wide) and optimising so you only store detail about cells that actually are filled and etc. There's lots of different ways you can choose to light things, or just say gently caress it and use Unity's default one. If it works for you then it doesn't matter!
If I just bake my lighting, how will moving entities figure out how bright or dark they have to be? That's a part I never quite understood. I'm guessing if I'm storing lighting data that would be used for that, I might as well use that data to shade the level too. The only thing is that baked lighting would yield much better shadows.

Sex Bumbo
Aug 14, 2004

Rocko Bonaparte posted:

What's a good foundational basis for lighting in a tile-based 3d world? I'm starting to think about it for my situation since I'm reaching a point where I could actually worry about it. I asked about it earlier and saw some stuff about generating light information, but I have to admit I don't even know what I should be trying to do. At this point I assume that--given my map data is basically a 3d array--I should create a 3d texture representing my light levels at each location. I assume I then ingest that data into a shader. The lights I add affect that 3d texture and I apply all my logic for deciding how much an area of a level is affected by lights to that texture. Is this about right?

Do you have a reference image of what you want it to look like?

xzzy
Mar 5, 2009

Rocko Bonaparte posted:

If I just bake my lighting, how will moving entities figure out how bright or dark they have to be? That's a part I never quite understood. I'm guessing if I'm storing lighting data that would be used for that, I might as well use that data to shade the level too. The only thing is that baked lighting would yield much better shadows.

Well the light entities should still exist, right? Use that information to light your models. It's not unusual for engines to use different lighting systems for static and dynamic geometry.

ModeSix
Mar 14, 2009

xzzy posted:

Well the light entities should still exist, right? Use that information to light your models. It's not unusual for engines to use different lighting systems for static and dynamic geometry.

This.

Unity has a mixed lighting mode where you can bake lightmaps for static geometry and use dynamic lighting for dynamic game objects.

I believe it is set on the camera game object.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Sex Bumbo posted:

Do you have a reference image of what you want it to look like?

Ehh not really. In 2d the mapping would be calculated from something like:



Numbers are the light value at the center of each tile. Presumably, each vertex would look at the values in the spaces it corners and blend it together. This could then be extrapolated into 3d space. I believe Minecraft does something like this, for example. It sounds like I should instead try to use the built-in lighting stuff and then go off on a tangent if I figure out I don't like it for some reason.

Rocko Bonaparte fucked around with this message at 23:47 on Oct 9, 2015

Sex Bumbo
Aug 14, 2004

Rocko Bonaparte posted:

Ehh not really. In 2d the mapping would be calculated from something like:



Numbers are the light value at the center of each tile. Presumably, each vertex would look at the values in the spaces it corners and blend it together. This could then be extrapolated into 3d space. I believe Minecraft does something like this, for example. It sounds like I should instead try to use the built-in lighting stuff and then go off on a tangent if I figure out I don't like it for some reason.

Stock minecraft doesn't do per-vertex lighting, it does per-block lighting like what you drew (but not what you described). The lighting algorithm would be quite similar to what you drew -- for each block, calculate the distance to the light, either taxicab or euclidian, and scale the lighting on the entire tile/block based on that. If you have an instanced tile rendering algorithm, you'll need to batch the lighting data into the instance data.

Calculating the distance isn't necessarily going to be cheap. You can notice minecraft does optimizations that result in lighting errors sometimes with blocks being lit when they shouldn't be, likely because it's caching the lighting data and not updating it correctly.

MikeJF
Dec 20, 2003




Does anyone have an algorithm for random but fairly regular points distributed across 2D space from a seed such that I can plug in a set of bounds and get the points in that region?

I suppose I could always parcel it into regular squares and randomly generate n points within using the square's coords plus the general seed as seed but I feel like there's gotta be a more elegant way.

MikeJF fucked around with this message at 06:22 on Oct 10, 2015

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Sex Bumbo posted:

Stock minecraft doesn't do per-vertex lighting, it does per-block lighting like what you drew (but not what you described). The lighting algorithm would be quite similar to what you drew -- for each block, calculate the distance to the light, either taxicab or euclidian, and scale the lighting on the entire tile/block based on that. If you have an instanced tile rendering algorithm, you'll need to batch the lighting data into the instance data.

Calculating the distance isn't necessarily going to be cheap. You can notice minecraft does optimizations that result in lighting errors sometimes with blocks being lit when they shouldn't be, likely because it's caching the lighting data and not updating it correctly.

There's apparently a smooth lighting option in Minecraft now--or maybe that's one of the mods I've been using. I've been playing it a bunch and saw that hiding in there after looking it up a little bit. Nonetheless, I did draw one thing here and while writing something else. I guess to fully-represent things, I'd be talking about something like a shader that blended the values a little bit so it did not look like a series of progressively lit squares with stark boundaries.

I'd assume the 3d texture would basically cache the current lighting. I don't expect to be moving lights around much, but I do want to have light switches. I don't have a 100% clear idea of the final game I'm trying to make, but all of the concepts involve a darker mood with things happening in the evening. I just looked up what it would take to get that working in Unity, and it's much less trivial than just doing a one-time bake.

evilentity
Jun 25, 2010

MikeJF posted:

Does anyone have an algorithm for random but fairly regular points distributed across 2D space from a seed such that I can plug in a set of bounds and get the points in that region?

I suppose I could always parcel it into regular squares and randomly generate n points within using the square's coords plus the general seed as seed but I feel like there's gotta be a more elegant way.

Sounds like a noise of some kind to me? Perlin/simplex would be a good start.

Pizzatime
Apr 1, 2011

Figured it wouldn't hurt reposting this issue from the Making Games Thread in here, too. Please tell me if that's bad form.

Been trying to change the line spacing of text in Haxeflixel. Using FlxText, it's possible like that (Text1 is an FlxText):

NewFormat = new TextFormat("assets/fonts/SkullzFontv1.ttf", 16, 0xF074d8f, false, false, false, null, null, "left", 0, 0, 0, 1);
Text1.textField.setTextFormat(NewFormat);

The TextFormat is being ignored using FlxTypeText, though, which is what I'd like to be using: https://github.com/HaxeFlixel/flixel-addons/blob/dev/flixel/addons/text/FlxTypeText.hx

Here is FlxText, for reference: https://github.com/domrein/Flixel-Haxe/blob/master/org/flixel/FlxText.hx

Maybe there could be some way to figure out what about FlxTypeText is leading to the TextFormat being ignored? Thank you!

DStecks
Feb 6, 2012

How do I make Unity stop throwing this error: "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed." ? I can't not use "new" when I'm instantiating an object.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I think I can articulate what I don't get about Unity's built-in light baking system now that I think back to when I did level editing for Quake and Half-Life. In those cases, you could have light switches just fine, and they would transition to different baked effects based on the light setting. I don't see anything obvious when googling showing how to do this in Unity. In fact, I'm reading that having separate light maps is a technical limitation; I have to engage in shenanigans when baking lighting if I want to have multiple light maps to switch between. So is this not normally a thing with Unity?

Bondematt
Jan 26, 2007

Not too stupid

DStecks posted:

How do I make Unity stop throwing this error: "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed." ? I can't not use "new" when I'm instantiating an object.

Top answer should help: http://answers.unity3d.com/questions/653904/you-are-trying-to-create-a-monobehaviour-using-the-2.html

xgalaxy
Jan 27, 2004
i write code

DStecks posted:

How do I make Unity stop throwing this error: "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed." ? I can't not use "new" when I'm instantiating an object.

You can't use new when creating any instance of a class that derives from MonoBehaviour or when creating instances that derive from UnityEngine.Object. You have to attach MonoBehaviours to GameObject's and create GameObjects by calling Instantiate:

See: http://docs.unity3d.com/ScriptReference/Object.Instantiate.html

If it is a regular C# class or struct using new is fine.

ToxicSlurpee
Nov 5, 2003

-=SEND HELP=-


Pillbug

DStecks posted:

How do I make Unity stop throwing this error: "You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed." ? I can't not use "new" when I'm instantiating an object.

It really isn't allowed because of how Unity works. Use Instantiate. You would use GameObject foo = GameObject.Instantiate(bar); instead of = new GameObject();

MikeJF
Dec 20, 2003




evilentity posted:

Sounds like a noise of some kind to me? Perlin/simplex would be a good start.

Ehhh... but I want to generate points, not a field.

Also, I want consistency. Like, I want to be able to plug in 'get me a square from x20y20 to x40y40' and 'x30y30 to x50y50' and the overlap between the two areas would be consistent. But anywhere in the infinite xy space Basically, this is closer to seed-based procedural terrain generation. But with dots.

I think the 'segment space into squares and use the coordinates of the square as seed' approach might be the way to do it.

German Joey
Dec 18, 2004

MikeJF posted:

Does anyone have an algorithm for random but fairly regular points distributed across 2D space from a seed such that I can plug in a set of bounds and get the points in that region?

I suppose I could always parcel it into regular squares and randomly generate n points within using the square's coords plus the general seed as seed but I feel like there's gotta be a more elegant way.

It made me laugh, and also puke a little bit at the same time, that when I clicked on this thread for the first time in a long while, that the first thing I see is a question involving random numbers and some clueless guy responding "AHHHh, SOUNDS LIKE jUST THE PERFECT SPOT FOR A BIT OF THE OLE PERLIN NOISE, MY gOOD GOON SIR." :monar:

It's a bit unclear what you want here. I can see three ways to interpret your question:

  1. Do you want what is pretty much an evenly spaced grid of points, like this:



    except that instead of a precise coordinate for each point, the point lies in a random location in the black circles? If so, that's very easy, all you need to do is add a random number around zero to each point's x and y value.

  2. Do you want a field of K random points within some space of dimensions MxN such that any regularly-spaced subspace of size LxL will have about K*L*L/(M*N) points per window? (e.g if you had a 100x100 space filled with 100 random points and looked at 20x20 windows, you'd want about 4 points per window) Then you want to use your regular squares idea, except there's no need to recompute the random seed for each cell. This kind of approach isnt considered inelegant at all. In fact, this class of algorithm has a formal name - a Monte Carlo method - and has been used to solved problems that people previously considered impossible to solve without it.

    In your case, first, break up your space into a grid, as you say. The important thing to think about here is how finely you want to space your grid. The more you want to overlap windows, the finer the grid needs to be spaced. For example, for a 100x100 grid and 20x20 windows with N points per window, if you want to ensure you have the same number of points for 20x20 windows starting at every 10 coordinates (e.g. windows starting at x:0/y:0, x:0/y:10, x:10/y:0, x:10/y:10, etc), then your grid spacing needs to be 10x10, not 20x20, and you'll subsequently look for N/4 points per 10 by 10 grid space instead of N points for every 20x20. (This is because of the Nyquist-Shannon sampling theorem, if you're interested). Likewise, if you want 20x20 windows starting every 5 coordinates, then you'll limit each 5x5 grid space to N/16 points.

    Anyways, now you have a grid, and so the next thing to do is start shoveling points into it. For now, think of each grid cell as a bucket. We want N points in each bucket, and there's a bunch of different ways to get that depending on what kind of spacing constraints you have. The most straight-forward is to just loop over each bucket and generate N random points (x from 0 to grid width, y from 0 to grid height) in each of them, adding the grid cell's starting x/y offset to each point. That's the simplest/fastest method by far. However, note that this method doesn't actually do anything about spacing; you could end up with two grid cells that have all their points along adjacent walls. What you can do about this is to use some kind of importance sampling, which means to reject a random point if it's within a certain distance to other already-generated points (note you need to check not only the current cell's points but also all adjacent cells' points). However, this can be really difficult or very time-consuming depending on your requirements. You can help the algorithm out by generating the random numbers in a more sophisticated way, but this can get fudgey. A more predictable way is to use "Poor Man's Importance Sampling," which means to just generate way more points than what you need, say, N*N points per cell (the more points you generate, the more even your spacing will be in the end, but the slower the algorithm will be), and then loop through the cells, chucking out the point that's closest to any other point on each pass. (again, remember that you need to check not only the current cell but all adjacent cells for this) Eventually, you get down to N random points in each cell, just like what you had previously, except now they should be spaced a lot more evenly.

  3. Do you not actually want a regular grid filled with random points, but something that's kind of like a grid, but slightly random? That's called a random mesh. In that case, look into Voronoi diagrams that have had Lloyd relaxation applied to them. The more the diagram is relaxed, the more regular it will be; of course, the slower your code will be too. Something like this shows the idea, if you look at just the dots and not the shapes: http://www.raymondhill.net/voronoi/rhill-voronoi-demo5.html You could also use something like Lloyd's algorithm on the N-points-per-bucket method from above, although I'm not sure whether it'll actually be more computationally efficient than the N-squared-points-per-bucket method for a given variance of closest-point-distance because you'll need to compute extra stuff. It depends on how much you care about computational efficiency, I guess.

German Joey fucked around with this message at 14:04 on Oct 11, 2015

MikeJF
Dec 20, 2003




Thank you very much! I basically want a monte carlo method. I'll look up more on specific implementations of those, there may be one that suits me best.

MikeJF fucked around with this message at 12:03 on Oct 11, 2015

Sex Bumbo
Aug 14, 2004
You could use this http://mathworld.wolfram.com/HammersleyPointSet.html

Jewel
May 2, 2009

Here's a neat series of articles from a developer on The Witness about point distribution (for foliage and light scattering, in this case):

http://mollyrocket.com/casey/stream_0013.html
http://mollyrocket.com/casey/stream_0014.html
http://mollyrocket.com/casey/stream_0015.html
http://mollyrocket.com/casey/stream_0016.html

Each link is fairly short, they're definitely worth taking a look at.

TheresaJayne
Jul 1, 2011

Rocko Bonaparte posted:

Does anybody have an existing, nice little angle calculation helper? I'm dealing with shenanigans like testing if something is rotated to -90 degrees, and finding out instead it's rotated to 270 degrees. I'm scribbling it as a I go, but I am willing to shamelessly draw upon some helper code if there is some.

If you just want to make it turn the least distance why not calculate the angle, then if the result is >180 go the other way!!! -(360 - result)

Ranzear
Jul 25, 2013

Rocko Bonaparte posted:

Does anybody have an existing, nice little angle calculation helper? I'm dealing with shenanigans like testing if something is rotated to -90 degrees, and finding out instead it's rotated to 270 degrees. I'm scribbling it as a I go, but I am willing to shamelessly draw upon some helper code if there is some.

atan2(sin(A-B), cos(A-B))

AFAIK this always gives the smallest angle (not sure if always positive though) between angle A and angle B. Just absolute value it to test for a 'cone', divide by absolute value for a turning direction, etc. I now live by it for Caliber stuff (though still normalize all my angles).



Caliber now has:

Chat. Teamchat. (Dis)Connection messages.
Sounds (Server even sends some from the fog).
New modules, which now have costs.
Some little menu descriptions on tanks and modules.
Drop pods (as spawning delay).
A server-cpu-saving adaptive tickrate.
Reload bars.
The major Firefox bug (white tanks) fixed. (Also, FF never liked BeamDuel's sounds, but the Web Audio API works great)
A bunch of tweaked energy mechanics.

and a bunch of other crap I can't remember.

Ranzear fucked around with this message at 10:33 on Oct 12, 2015

Sex Bumbo
Aug 14, 2004

Ranzear posted:

atan2(sin(A-B), cos(A-B))

If you use this, make it really clear in the function name or whatever that it's calling three trig functions and should probably not be in a tight inner loop.

emanresu tnuocca
Sep 2, 2011

by Athanatos
Why not just idk
code:
if(angle < 0)
      angle = angle + 360;
return angle % 360;
It will never return negative angles but you'll just get used to thinking about angles from 0-360 sooner or later.

If you really want to get angles between -180 to +180 you can do
code:
if(angle > 180)
     angle = angle - 360;
if (angle < -180)
     angle = angle + 360;
return angle % 360; 
or something along those lines... probably needs some debugging.

Edit: hmmm yeah this won't really work for angles that are way out of range, might actually want to first do the modulo operation and only then correct the range I guess. h

emanresu tnuocca fucked around with this message at 18:49 on Oct 12, 2015

Sex Bumbo
Aug 14, 2004
Do you people seriously store angle measurements as integers?

E: wait this is C# or something isn't it.

Sex Bumbo fucked around with this message at 19:05 on Oct 12, 2015

Blue Footed Booby
Oct 4, 2006

got those happy feet

MikeJF posted:

Thank you very much! I basically want a monte carlo method. I'll look up more on specific implementations of those, there may be one that suits me best.

I have no idea if it's what you want, but "Poisson distribution" is fun to say.

Pizzatime
Apr 1, 2011

Having issues with exporting to Flash with Haxeflixel. Neko works fine, Flash has text cut off due to a too small textfield and blurriness. Would anybody know anything?

Adbot
ADBOT LOVES YOU

Ranzear
Jul 25, 2013

Sex Bumbo posted:

If you use this, make it really clear in the function name or whatever that it's calling three trig functions and should probably not be in a tight inner loop.

I use it in feedback mostly. "Turret needs to aim at x,y, which way does it need to turn?"

I'm coming from JS/Node though, where math is cheaper than lookups.

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