New answers tagged

1

Calculate AC (xC - xA, yC - yA) Normalize it Multiply it by r Add that vector to A : done !


2

I believe you should still want to use a perspective projection instead of orthogonal one, as there is still a perspective in it. There's some ways on how to achive it. One would be using a perspective projection and tweak the fov to achieve the narrow camera effect and maybe a low resolution framebuffer (OpenGL) and resize it to get a pixelated effect. ...


1

Use an orthographic camera instead of perspective camera.


3

Is memory efficiency really a problem? 2D textures are not typically huge enough to cause issues. Splitting the tilesets into too many textures may even cause problems in itself, since switching textures is not always cheap on the GPU. You should probably just optimize for your development efficiency at this stage. Unless you're intending to have loading ...


0

I've been proposed for using awesome Clipper library. It is exactly the thing I need. "For constructing the union of 2D polygons you can use Clipper library."


-1

You want to made a game for fun or more like a project ? For myself i prefer to made a 2D game but all by myself (without any tools, just a IDE and some libs) instead of a 3D game using a game engine. That's better to understand game internal functionnement. But if you want to made a game only for fun you can do both 2D/3D, depending of your game idea.


-2

A grid. Implementation is more simple and often times superior in performance. Edit: Hu, why the downvotes? This was more of a follow up info to the accepted answer. The OP asked for alternatives. You can find grid vs. quadtree discussions everywhere. Bottom line is a quadtree doesn't deliver a better performance (often times it's slower) than a simple grid ...


1

If I understand your question correctly this can be done using a bit of vector math. I've created an example in Javascript so please keep in mind that many of the mathematical operations I'm doing here can be done in Unity really easily using the built-in classes and methods. The ball will follow your mouse when you hover it over the window. I recommend you ...


0

Instead of hard restrictions you can use opposing forces. You want to simulate a rubber band between the two objects. That sort of force can be simulated by applying a push every frame that equals "distance to object" to the power of "your rubber band's springiness". If you want to increase the effective distance that object A can travel away from object B ...


0

By some magical way I found out that your camera is orthographic. You don't use Camera.current.fieldOfView for orthographic cameras, instead use Camera.main.orthographicSize. Adjust the line in the second if condition to be Camera.main.orthographicSize = Mathf.Lerp (Camera.main.orthographicSize, zooom, Time.deltaTime*smooth);


0

Well, the title is "Zoom In and Switch Scenes", so I'm gonna tell you how to do both of those. In order to achieve a zoom effect, you'll need to modify the field of view of the camera, which I believe is simply called camera.fieldOfView. To change scenes, you'll first need to make sure that you are using UnityEngine.SceneManagement; So that you can use ...


0

Yes, I would create a separate Bullet object in global coordinate space. I guess you know how to transform a point from the gun's coordinate system to the global coordinate system. A simple way to get a global direction vector works like this: // Coordinate system of the gun Vec3 gunStart = Vec3(1, 0, 1); // Local starting point of the bullet (tip ...


0

When you press key for the shot then create bullet object. Of course. You need to create class for your bullet. So you must to have two variables which will remember the direction of the bullet.


1

The algorithm you are using right now has a runtime of O( n^2 ). A tree structures can help you get that runtime lowered. Quadtrees have O( log(n) ) From that you can calculate if you will benefit from a quadtree.


1

The animations and logic for attacks can be broken down into individual logical units and then sequenced via data files. For example, you might have code like this: AdvanceBehavior(entity, target, speed) FallbackBehavior(entity, target, speed) SoundBehavior(entity, sound_id) AnimateBehavior(entity, anim_id, speed) and then you can have a data file that ...


0

To create this effect convert the pixel to greyscale: float grayscale = dot(color.rgb, float3(0.3, 0.59, 0.11)); Then return red above the threshold and return black below it (while preserving the alpha). See what threshold value works for you.


0

I'd write a little script like this and attach it to the object displaying the sprite: [RequireComponent(typeof(SpriteRenderer))] public class SpriteSwitcher : MonoBehaviour { // Populate this array in the Unity Inspector window // to contain the sprites you want to switch between. public Sprite[] sprites; SpriteRenderer _spriteRenderer; ...


1

Should I have a base class for the battler which has all the common methods and than inherent each character from that class with its own attack sequences? If you have a lot of battler types, I don't think you would necessarily want them all to be their separate class if they are very similar to each other otherwise. One approach would be to have them all ...


0

There's nothing particularly special in how font rendering is handled in OpenTK. OpenTK - among other things - contains an OpenGL wrapper. And as such any techniques you'd use to render text in OpenGL apply here, namely: Using bitmap fonts - loading font atlas texture and rendering textured quads. BMFont Using geometric primitives (triangles/quads) to ...


1

Your image is 64x64 and your Pixels To Units setting is 100. That means at native size your Sprite is 64/100 = 0.64 units wide. To make this 3 units wide, you'd need to set your local scale to 3/0.64 = 4.6875 Or, you can change your Pixels to Units setting to 64, then your sprite will come in at exactly 1x1 unit, and a local scale of 3 will make it 3 ...


0

Swing / Java2D doesn't have a concept of a camera, but what you can do is store the transform of the camera, and apply that first before any other transforms. Also note that you are almost certainly going to run into unpleasant performance problems if you're not using an OpenGL-based rendering system. (I speak from years of painful experience.) I would ...


1

The problem is in your game loop You are limiting your rendering fps to your game world fps. You should update your world on a fixed timestep and either leave the render timestep to vsync or limit to something like 60.. You're using non floating point variable types where you should be using floating point math. This adds imprecision and can cause ...


0

Turns out that I was using sfml 2.3.2 which I guess isn't fully compatible with qt creator so I tried sfml 2.0 and it suddenly worked. Here is a link to a video describing how to link SFML to Qt Creator: https://www.youtube.com/watch?v=VWvD4mUpyfU


0

You can try something like this. float step = speed * Time.deltaTime; Vector3 newDir = Vector3.RotateTowards(transform.forward, directionOfTravel, step, 0.0F); transform.rotation = Quaternion.LookRotation(newDir);


2

It could be that the attack timer never reaches 0 as the delta time will keep removing time which will eventually cause it to go negative. Instead check if the timer is less then or equal to 0 so if it goes negative the attack animation is stopped. else if (attackTimer <= 0f) Note: You should add an "f" behind numbers that you want to be floats because ...


1

Unfortunately, I don't have enough reputation to add a comment to your original post. Here is my go at a partial answer! Here is where you populate the top row with 30 white boxes. for (int i = 30 - 1; i != -1; i--) { hitbox[i][0] = 1; } It looks like your boxes are 20x20 because tmp[0].position = Vector2f(y * 20 - 10, x * 20 - 10); My honest ...


0

Switch statements are supposed to be surrounded by curly braces. switch(level.hitbox[y][x]) { case 1: tmp[0].position = Vector2f(y * 20 - 10, x * 20 - 10); tmp[1].position = Vector2f(y * 20 - 10, x * 20 + 10); tmp[2].position = Vector2f(y * 20 + 10, x * 20 + 10); tmp[3].position = Vector2f(y * 20 + 10, x * 20 - 10); ...


0

As far as I understand your problem, you can try the following. Firstly, depending on the screen resolution, you have to scale the background object so that it occupies the entire space. This can be done using the something like the following code. newWidth = Screen.width / textureSize; newHeight = Screen.height / textureSize; transform.localScale = new ...


0

I'm not sure if I understood the problem right but maybe you can limit the Z rotation of the character to a certain angle so it can't tumble when you are going downhill. But if you also want your character to be able to flip in the air at certain heights for extra points or whatever your score system is, you can set the rotation limit only if the player is ...


0

Unity has a separate function for touch screen devices. Here' the code. Note that functions MoveLeft() and MoveRight() are exaggerated, so you need to replace them with your own. C# Code: function Update () { for (int i = 0; i < Input.touchCount; i++) { Touch touch = Input.GetTouch(i); if (touch.phase == ...


1

In Alto's Adventure, the terrain is dynamically generated over time, by concatenating prefabricated patterns (for example the super steep slope where you can perform a triple backflip, or any other soft slopes) in a randomic way to keep the game various from play to play. A possible implementation can be treating these "pieces" of terrain as vertices, from ...


0

Lets start of by defining a few variables. Lets say that o is the position of the player, d is the point that we want the player to look at, c is the position of the camera and dist is how much do we want to move c towards d, were dist is a float between 0 and 1. float cX = (dX - oX) * dist + oX; float cY = (dY - oY) * dist + oY; In case you want to move ...


1

Unfortunately this is quick to answer: You can't from a single image. To determine the intrinsic camera parameters (like lens distortion) you'll need at least a few pictures and more known points. If you want to read more about it, Google for "camera calibration" or lookup how some libraries do that, e.g. OpenCV. From a single image all you could get are ...


0

The method I would choose for this is to just use your existing map for as much as possible. This is essentially your first approach. Yes, you will need to figure out the IDs of trees (and other relevant objects), but on the plus side you don't need to make any changes to how you're creating maps, storing them, loading them, rendering them... Regarding ...


2

Touchscreen devices do not have keys, so you need to think about another input method. A quick and dirty solution to adapt a game designed to be controlled with directional keys to a touch device is to use a "virtual keypad". Use the Unity UI system to create four buttons on the screen the player can tab on, and bind each to an appropriate function which ...


6

It shouldn't have any impact. You should not be implementing zoom by scaling or otherwise messing with 'the Z factor' (whatever that is) of your objects in the world. You should be implementing zoom by adjusting properties of the camera and projection (field of view, camera position). The camera and projection properties only come into play when you ...


0

Rather than fiddling with angles, you can use a cross-product to know in which direction you should rotate. Don't be scared by the theory dump : it's actually pretty simple to use! Let C be current and F be future. They are both 3-dimensional vectors, with z = 0. Then the cross-product P = C×F has the following properties: Px = 0 and Py = 0; Pz = CxFy - ...



Top 50 recent answers are included