Hot answers tagged

12

Going to try and doodle up what I mean here as soon as I finish typing this, but: What about merging the two? Use the second (occlude by base) for everything that isn't a wall and the first (occlude by tops) for lighting the walls? You actually did this by accident in your second example, with the wall that goes off the bottom of the image. Extending ...


9

I tried this. It was hard, but I did it. Left is GIMP, top-right is a Box2D debug renderer, bottom-right is a build shell Code repository for reference The full code is on github here. It's scattered in a whole lot of files, so it's a bit big to put here. See below for an explanation of the technique. How? I used ImageMagick, Potrace, Node.js ...


6

I suspected OP already knew this approach so I mentioned it in a comment as just a starting point, but I'll try fleshing it out a bit more... Most physics engines divide dynamic objects into two groups, "awake," and "sleeping." Objects sleep when they sit at rest, and wake when moved or accelerated by some outside influence. A sleeping object behaves like ...


4

I understand you are dealing with both box obstacles and gaps. The way it was described, I can see three possible situations. Correct me if the game is designed differently. With the first, there are no obstacles before the gap, at least no obstacles that the player can jump atop. In this case, you would need only a fix max width for the gap. In the ...


3

First Question: The dot product basically tells you how much two vectors are pointing in the same direction. So if a light points directly against the normal of a surface the surface will be brighter than if it points at it in an angled way or away from it. If you are struggling with getting this to work, I would advise very heavily against trying to ...


3

Do it at the generator level: Always generate your level using a selection of passable gaps / obstacles section prefabs. If two successive sections are not passable mark them as such so the generator does not put both in succession and/or adds some space between them. These sections will also instruct the AIs on how to clear the obstacles.


3

R.U.B.E. does this. The feature was included with the addition of samplers since v1.6.0. This tutorial video gives a description of how it can be done. To test, I used Anko's and Xander's images for comparison. First I imported the image of the sword and heart wand into RUBE (I'm on v1.7.0) and created some samplers (shown by dashed outlines) over them. ...


2

A newbie's answer. Suppose the orange marked place is the position for your enemy to jump, you make a trigger on the orange x mark of the object on the prefab and tell the enemy ai to jump when the ai hits the trigger. Simple Answer.


2

To be physical, you need to calculate friction based on the magnitude of your velocity. You can simply remove the if checks when calculating friction and store a "friction constant" instead of a "friction force." You are already essentially doing this because m_fFriction is a double and not a vector, you are just thinking about it wrong. The friction ...


2

You can set spotlights and simulate light by a raycast algorithm and interpolate to have the light intensity, here's an approximation in javascript that i wrote to test something similar some time ago, read it carefully, it's not clean as it could be but it can help you to find out your own solution. var canvas = ...


2

This problem is a bit difficult to think about because it's unphysical -- engines have a thrust which equates to acceleration and not top speed. So I think to fully answer this question, you need to remove it from a physical framework and just think of it in terms of vectors. To be clear, I will use "speed" whenever I am talking about the overall quantity ...


2

First off, you should really store the tiles in a 2d array. As far as I can tell from documentation, sf::View has a getViewport() method. This method gives the coordinates of the top-left point of your view. Next you will need the coordinate of the mouse, in relation to the top-left of your window. Finally, you add the two coordinates together, and you'll ...


2

Figure out your mouse position in world space and divide by the tile size. Basically keep track of where your upper left corner is in world space, add the mouse position to that (with appropriate scaling etc.) and then divide it by your tilesize.


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 ...


2

I won't be able to make an image for you, but one trick you could do to figure out if a piece of wall should light up is to take advantage of the 'alpha' channel for determining the direction the pixel is facing, as opposed to the opacity of the pixel. You could then determine whether the pixel should be lit between the light source and the facing of the ...


1

Then I thought about using meshes, but I think that meshes might be too hard on the engine and cause some slowdown. Let me check my clock...yes, it is 2016, having 1 mesh shouldn't slow down anything. What you need here is a tile based terrain (e.g. terraria) with marching squares. Marching squares is an algorithm, wich is made to smooth out 2d tile ...


1

The first scenario is called Panning or sort of Parallex without having Camera Follow. It will totally up to you that how you handle behavior of Camera. That means pausing game, move camera ahead, you can do it manually like other objects. In second case I think you are asking about Smooth Camera Follow that would follow your character in smooth manner. ...


1

I think the first one you are describing most closely matches a Fixed 2D camera and the second is a smooth floating or smooth sidescrolling 2D camera


1

I asked just this question on SO a while ago, same language aswell, and no one didn't really care, so when I found the solution I didn't really bother to put it up there, but now more people are interested and I am glad for that, so now I will post the answer here. Here's my original code, it's the exact same thing as yours, just a bit more clear of what ...


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 ...


1

SFML has a few good functions that allows you to do what you want a bit simpler window.mapPixelToCoords(sf::Mouse::getPosition(window), viewRect); That line of code will convert the mouse position relative to the window (sf::Vector2i), to a world coordinate (sf::Vector2f). I have the window as an argument there, or else it will get the mousePos relative ...


1

Don't get caught up in the exact numbers used in the example. Those are not the main point. It's how they are relative to each other. You see that xhdpi 200x200 is twice as big as mdpi 100x100. Notice the if in the example. List of densities: xxhdpi: 3.0 xhdpi: 2.0 hdpi: 1.5 mdpi: 1.0 (baseline) ldpi: 0.75 Sample example but with different numbers: ...


1

I managed to solve my problem. I used the shaders from this post: http://forum.unity3d.com/threads/sprite-renderer-mask-on-specific-sorting-layer.356824/#post-2310992 And a simple grey circle for the "blur-free" circular zone. The pre-blurred sprites used the "Stencil Draw In Mask" one, the regular sprites used a shader that was the same as the above, but ...


1

From you code I can't tell what the ownerv vector is so I can't tell you why it's giving you the wrong result. But to do it from scratch, according to Wikipedia's article on vector projection, you can do the following; Create a vector a that is the direction from o to v. Create a vector b that is the direction from o to n. Let d be the dot product of a ...


1

It looks like a wrong approach. Check this tutorial: https://unity3d.com/learn/tutorials/modules/beginner/2d/sorting-layers In order to sort your stuff properly and automatically you can use depth (z) and/or sorting layers within objects at the same depth and/or order in layer within objects in the same sorting layer. It's probably reasonable to have ...


1

Ok, so just of the top of my head your going to want to make a new circle(2d) and apply a texture to this then write something along these lines (and attach it to the object) Pseudo code: private gameobject player private float scale; update{ face the player (using transform.lookat(player)) float distance = ...



Only top voted, non community-wiki answers of a minimum length are eligible