New answers tagged

0

Please take a look at this; if I'm on the right track, I'll expand it and add narrative. You'll draw a single terrain prefab over and over, having it morph based on the descriptions fed in via the per-instance buffer. Example description elements: Matrix worldMatrix; UINT terrainTextureArrayIndex; Pickups can be handled similiarly. Draw a single cube ...


0

Design some level blocks with combination of obstacles coins etc. (Maintain a parent child relation). Make a LevelGeneator script which will contain a Array of Transform or Gameobject. Assign the level blocks to the Script object in inspector. Randomly take a Transform and give it some force and make SetActive(true). If its still not clear, let me ...


0

It is not that complex as you think. May be you are confusing because you have a tiled map. So the basic solution is to keep object at center (0,0) and if it has children then keep children's position (local position, position w.r.t its parent) should also be at center (0,0). Now in case of tiles you have to make sure that the whole tiled map should be ...


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


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


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


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


0

The solution is simple as that: P = Circle center r = radius or the circle You get the closest point from the circle center to the polygon (C) (I assume you got that already) Get the distance from the closest point to the circle center (D) = C-P Normalize that distance to get the unit vector (N) Get the signed distance to the edge/vertex and take the ...


0

You probably need a skybox or a skydome. A skybox is a box around the camera, and is always centered around it. Basically a model, wich isn't get transformed by the view matrix.


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


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

Something that you could consider is using Bézier Curves. Find some way to determine the points that generate a curve that fits each corner of your race track. Use the function for that particular curve to calculate collision. Here is some more reference for using Bezier Curves in the context of game development.


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


0

The issue is due to memory usage, wasted memory bandwidth and/or the time it takes to rescale it to the proper size at load time. In the case of Android using the 2D UI the image will be scaled once to the proper size at load time but this takes a bit of time and the larger original will be kept in memory if a reference to it is kept. In the case of direct ...


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.


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


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


-1

The easiest way is probably with an emulator, the pront screeb button, and an eraser tool. You could also open the game files with an editor, and copy them.


0

This is how I would do that (pseudo-code): class Vector { var float x; var float y; function Vector (float angle, float magnitude); // constructor function add(Vector); // adds new vector to current vector function angle(float new_angle); // returns or sets angle function magnitude(float ...


0

Well, normally, you would just produce 1 graphic, at the highest resolution you will be publishing to. Then you would just use the Unity tools for setting mip-map levels. You would then modify settings like 'pixel perfect' or 'texture type' (compressed, truecolor, etc.) to get the best look for the compression you choose. Creating resolution independent ...


0

The is no problem with your repaint() method. The problem here is that the Sparx you update and move is a different Sparx then the one you render/paint. In your Board class you create a new Sparx instance and this is the one you render out. This is a different instance from the one you create in your StartingClass and update the position of. Simply ...


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


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


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

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


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


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.


0

It looks like you're using acceleration in a weird way in your engine, so I can't give you a 100% fool-proof answer you can directly implement into your code, but I can take a shot at it. You'd want to apply your friction to your current speed, not your characters acceleration. Try to change your code to this instead: if( curVel.x > 0.0f ) curVel.x ...


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

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.


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


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


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


3

On line 161 you return too early from FlattenPoints. Move the return statement outside of the for loop and everything appears to work correctly.



Top 50 recent answers are included