New answers tagged

1

First, this line: float dotProduct = (_one->velocity().x() * collisionNormal.y() + _one->velocity().y() * collisionNormal.x()) * remainingTime; is calculating the wrong quantity (it should be x * x + y * y). Second, if you want to slide, you simply need to set the component of the velocity parallel to the normal of the collision surface to 0, and ...


0

Set their position to be almost perfect - account for floating point precision. So if your player is 8 units tall, and your platform is at (5,6), and you land on the platform, then: When you see an imminent collision, set the player's y position to 6+8+0.01 6 is the y position of the platform. 8 is the player size offset. 0.01 is the floating point ...


3

So upon further inspection your problem actually has nothing to do with coordinate system conversions. This could have been made more clear by not naming your axial coordinates X and Y but rather Q and R. The problem you're actually having is bad loop conditions. The original code sample produces delta q's and r's which you try to convert, in your for loops, ...


6

As Vector57 noted, the problem is you are using the wrong coordinate system. The algorithm described is meant to be used with cube coordinates, which have x, y and z components: This may not be obvious from the algorithm's pseudocode, but that's because it's a simplification of this: var results = [] for each -N ≤ dx ≤ N: for each -N ≤ dy ≤ N: ...


3

D* Lite if you want AI that behaves in the way that a human might when exploring a completely new and unknown area, needing no prior knowledge of the map except for the coordinates of start and goal, and which can adapt to a changing map. This algorithm is both conceptually simpler and more efficient than the original D*, effectively obsoleting D*. It's been ...


1

You're not getting the angles properly, the sum of the internal angle of a simple polygon can be calculated with the formula: π(n-2). We then need the external angle which is the angle from point to point, this can be calculated with : π-internalAngle. Assuming the first point is in the lower left and there's no rotation this code should work. void ...


2

I understand you also had problems drawing a line from point to point. I recommend you look into "Bresenham's Line Algorithm" as it typically gives the best result. Here is a Wikipedia article about it. The article includes pseudocode for the algorithm, including one that only relies on integer arithmetic. I won't be posting it here as I encourage you to ...


0

There are many ways you can do it. A* and such is a good option, but lacks in documentation. You could do something like place nodes quasi-randomly around the map and check which nodes can see each other and build a little web of nodes. Not the most optimal but easy to understand.


0

It looks to me like you can use a variant on a Poisson disc sampling algorithm to achieve this. Check out Mike Bostock's wonderful visual demonstration of these algorithms, particularly the explanation of Bridson's algorithm about a quarter of the way in. Here you store your points in a grid where the cell size is r/sqrt(2) - that way if all your points ...


0

tl:dr; Read the first and very last paragraph With this approach, your AI will likely attempt to always use the optimal strategy, but the way you code it can easily lead to abuse. So, when considering how to evaluate "the best state for the AI" keep these examples in mind: Example 1: (the problem you currently see) Player team is full of extremely high ...


6

The easiest way is giving a variable "conected = false" to every electric item and then, starting from a energy source, do the following: function adjacents(tile){ return [ getTile(tile.x-1,tile.y-1), getTile(tile.x,tile.y-1), getTile(tile.x+1,tile.y-1), getTile(tile.x-1,tile.y), tile, getTile(tile.x+1,tile.y), ...


3

Prison Architect uses "pieces" of cables, it is not all one long cable, it is a sum of lots of "pieces" (or squares, not sure how to define it): Image here (The bright green conected pieces are cables) I don´t know how they do it, and I bet they are not going to tell us, but I can tell you how I would do it. Assign each "piece" of cable an state (an ...


4

First of all, for uniformly distributed data, Knuth’s function i * 2654435761 >> 16 is definitely better than i * 2654435761 >> 8 because it shuffles more bits. An explanation follows. Consider the multiplication of numbers WXYZ and PQRS (all these letters representing arbitrary digits in any base) and see how the digits get added together in ...


0

For MLCG constants you want an odd number that's a multiple of five (assuming no explicit modulo). That'll be a weak PRNG. For Weyl like generators in integer you want an irrational scaled and rounded to odd...golden ratio and sqrt of two are good choices. That will give you a weak low discrepancy sequence. Neither of these tend to work well for hashing. ...


0

One way you could do this is to set a specific tag for each type of tile within the Inspector View of each tile in Unity3D. Then you could write code for it, a simple example being: void OnTriggerEnter() { if (tag == "redTileGroup") { // do something } }


2

As people have said in comments section, A* or (AStar) is a viable algorithm for this, and a good waypoint. Here you have a generic AStar implementation in Java so you can start with something. Please, ask if you have any question. import java.util.*; public class AStar { public static class PriorityList extends LinkedList { public void ...



Top 50 recent answers are included