Tag Info

New answers tagged

0

I think Unity uses Box2d? IIRC from an old read box2d uses some sort of spatial trees so that inactive colliders should not consume much CPU power. My guess is, check your draw calls which are very often the cause for lags on mobile, make the colliders invisible and see if it helps in your frame rate, good luck.


3

You're doing it wrong - very inefficiently. Instead of rendering lightsources to your "lighting framebuffer", render the lighting contribution. That would be a soft disk centered at your light source instead of a single pixel. Example disk: ... and you can render that as a sprite! (Additive blending, clamp to 1 for best results). You can now bind that ...


2

Byte56's answer is very good, especially for the example image given where simulating the movement of each "ball" in the line will work well. I'll give you an alternative idea however which might work better, or might be easier to implement if you are trying to work with a dashed line (with or without animation), something like -- -- -- -- Calculate the ...


0

I have found the solution to this somewhere else. Adding a bigger if statement such as this : private int elapsedTime = 0; //Declared at class level public override void Update(GameTime gameTime) { elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (elapsedTime > 500) { elapsedTime = 0; birdbox3.X += 5; birdbox3.Y -= 5; ...


0

You're using Update incorrectly. Update is called automatically every frame by Unity, on every component attached to every object (you can see this with the default comment that still exists in your code // Update is called once per frame). You don't need to call Update manually. I see you're aware of having conditionals in the Update loop. What's wrong ...


3

You get the path the same way you'd move the object when you shoot it. Just have a tight loop that simulates the movement of the object and keep track of the position every so often. Now you have a list of positions, if you draw a dot at each position, you have a dotted line the represents the path of the object if it were to be shot from that angle.


0

It seems to me that you haven't defined enough of what is happening in your system, to know how it should move. I.e., I think you are missing the forces involved when one of the two component objects rotates itself. In real inertial physics, nothing moves without force being applied, but it sounds like your model for the component rotation may not include ...


0

I solve the second problem. It was in front of me all the time. As I said, I was using this code as example. What this awesome answer doesn't explain you is that once you compile the code, if you select the sprite back on hierchy you'll notice two variables available, corresponding to the one you declare back in the code. My BIG mistake was not ...


1

I think you should break this up into multiple questions and try again. Offhand, I see 3 questions that all warrant their own detailed answers, but there are probably more that you can ask to get the detailed answers you wish for: Using 3D to generate 2D Sprites You can just use 3D as a way to render Sprites, i.e. by creating your animations, then ...


1

First, find the center: p0 = (C + D) * 0.5 Now, take the relative vector from the center to the point in question: p1 = (X - p0) Finally, take the dot product with the normals you might want: d0 = n0.dot(p1) d1 = n1.dot(p1) ... etc. Then, check to see if its greater than zero abovePlane0 = d0 > 0 abovePlane1 = d1 > 0 ... etc.


0

Let's say your "worm" is 100 pixels high, and his bottom edge is at 0 height. As you walk to the side, you'll find collisions (you know how to check if there's a collision, so I'm not going over that). If the pixel you're colliding with is LOWER than y + (h/4), where y is the height of the bottom edge (in this case 0), and h is the height of your worm (in ...


0

Question 1: As always, it depends, and on many factors. Not only it depends on how much stuff you're drawing, but also on the particular video card, drivers and OS. In general, the old way of doing things (immediate mode and fixed pipeline) will probably be fast enough for your needs. However, you should probably consider doing things the modern way ...


0

Other than being more performance efficient, I find it simply easier. It requires a little extra work to make sure your images are always within their bounds when creating the art, but it's a lot easier being able to see all the images you're dealing with at the moment. It's also easier to code, in my opinion. I simply have an array of objects like: sheet ...


0

I have done something like this just today. The key idea here is to use the new Unity UI and a world space canvas. Here are the general steps needed to make this work: Create a new canvas, set it to world space. (The size should not matter, but I have only started using the new UI system recently, so I am not 100% sure of that. It works with a size of 0 ...


0

Found an easy solution to the problem. I just compared the midpoint x-coordinate of the player to the x-coordinate of the intersection to see where the player was relative to the platform (i.e. left or right). If the x midpoint of the player's rectangle > x point of intersection rectangle, then he should be on top - otherwise, he's on the side of the ...


0

This is not something that you can cover in a question. To get proper results you need a physics engine that supports soft bodies collisions. Use something like this. Essentially the characters body is supposed to stick to the ground because it doesn't stop when it hits the ground. It's like a ball hitting a blanket, or a spring more precisely. So when the ...


0

Yes, there is a trick you can use here. Based off of your glitch and your code sample, I'm assuming that you're moving both the player's X and Y position at the same time, then checking for collision. Instead, move the player by its X velocity, then check for collision. If it has collided with any platform, then it must have hit the side of a platform. ...


0

Because Vector3 is a value type, not a reference type, you need to set transform.position if you want to affect its value. That is, Vector3 currentPos = transform.position; // ...changes to currentPos.. transform.position = currentPos; If you're using Visual Studio, you can find out which are value types (struct) or reference types (class) by either ...


0

Javascript has two kinds of types, primitive types and objects. The primitive types are few and cannot be added to, thus most of the types you encounter are objects which have reference semantics. C# has reference types and value types. Unlike in Javascript, you can make new value types with constructs like struct. Unity3D's Vector3 in C# is a struct and ...


1

It's definitely possible to have a common code base if you use cross-platform technologies such as Unity or HTML5 frameworks. Though you'll always need some platform-specific work (Facebook app creation, distribution on the app stores, integration with the payment services,...) Choosing the framework highly depends on your skills and preferences. If you ...


0

I strongly suggest you to start working on your first game to get enough skills and global knowledge on video game development before wondering about platforms or selling plans. Read about video game development (through books, internet...). Learn how to make a game. Fail at making a dozen of games. And only then you'll probably be confident and skilled ...


0

OnTriggerEnter2D is supposed to have a Collider2D parameter. As yours have none the method signature is different and that's probably why it's never called when a collision occurs. Also as explained in the documentation I would strongly suggest to use StartCoroutine in it's method parameter form instead of using it with a string parameter. I hope it ...


0

assert is your friend, if you get NullPointerExceptions that originates in your code (and not deeper into nested calls) then one of your objects is null, no matter how unlikely or impossible it seems. You have to assume that all assumptions are wrong and either step through the code and checking variables as you go, or - if that is hard due to the program - ...


0

I finally found a satisfying solution! @Thebluefish comment pointed me to the right direction with masks. The idea is to use a shader that draws the character in two passes: In the first pass the character is rendered normally, BUT being completely behind the bushes. In the second pass I draw it again, using a mask that olny draws the top part of the ...


-1

You can detect wether or not character is in the grass. Then draw only top-half of character.


0

Set the UVs from the (X,Z) or (X,Y) vertex coordinates of your light mesh (depending on your world setup) relative to the light center. vertex.uv = vec2(0.5, 0.5) + (vertex.pos.xy - light_center.xy) * scaling; Assign that fading texture to your light mesh and set the texture mapping to clamp (or clamp to edge) Use the scaling value to control the fading ...


0

It doesnt work, because you dont count fingers on screen, so no matter how many fingers will be on screen, touchDown always returns first touched coodrinates, next touches are ignored. If you want to use multitouch, then you have to make use of pointer variable in touchDown method. Actually i answered very similar question once in stackoverflow, and im sure ...


0

Eric Lippert presented a tutorial (in C# of course) on calculating Line-of-Sight with Shadowcasting for a square grid. The first five sessions define various objects used in the algorithm, with the final code private static Func<int, int, T> TranslateOrigin<T>(Func<int, int, T> f, int x, int y) { return (a, b) => f(a + x, b + ...


2

Update is called as fast as possible. The variable 'Time.deltaTime' is set to the actual amount of time that passed since the last call. If lag or something similar slows down the game, Update will still be called only once once the lag is over, with a high value of deltaTime. FixedUpdate is called at regular intervals. It will never be called more often ...


7

I was going to write this as a comment, but it ended up being rather long winded so I've turned it into an answer. The current answers are mostly correct, but a few things mentioned are misleading/wrong. In general, most game-play related tasks will go in Update. For example, you don't want to be polling for input in FixedUpdate (not because of ...


0

It's probably simpler to set boundaries on the camera set: camera.position.set(clamp(player.getX() + (player.sprite.getOriginX()), minScreenX, maxScreenX), clamp(player.getY() + (player.sprite.getOriginY()), minScreenY, maxScreenY), 0);


2

The problem is basically this: The LineRenderer is trying to connect the red dot positions. It's creating the green vertices to make a mesh. So the top line segment looks great. But then the LineRenderer tries to be economical, it reuses the vertices from the end of one line segment in the end of the second line segment. When there's a sharp angle, you ...


3

It's hard to know exactly what's happening without hands on but: OnMouseUpAsButton is only ever fired after Unity has performed its own successful ray cast (this happens in the background, during each frame so that Unity knows which objects to call the various OnMouse???? methods on). OnMouseUp() is called when releasing the mouse button over a collider. ...


1

I found this nice tutorial on DelphiGameDev.net: " So, the first thing we need to do is actually add our background. Previously we set this up in our DXTimer component, redrawing it before each animation. This limits us however and to be able to effectively scroll our background we need to set up a special class of sprite called TBackgroundSprite, much as ...


4

The Update function is called every frame. Its frequency depends on how fast the computer is able to render images. On a slower computer, Update is called less frequently than on a faster one. If you do time-based calculations, you can normalise them using Time.deltaTime which tells you how long it has been since the last time Update has been called (caveats ...


2

From: http://unity3d.com/learn/tutorials/modules/beginner/scripting/update-and-fixedupdate The time-step used in FixedUpdate is not variable. If your game starts to lag, when it catches up, you don't want >10seconds of physics in one update, so it is typically done in FixedUpdate which is called on a fixed-interval. For example: Update(float ...


3

Welcome to the wonderful world of continuous state motion planning. A few years ago I wrote a Gamasutra article on this topic. Here are some solutions to your problem: Navigation Meshes This works by constructing a graph of nodes and edges of your scene based on some simple rules. For instance, you can construct a Visibility Graph of the scene, which is ...


1

Simply choose the facing for the character that is closest to the angle of the shot. 8 sets of sprites would be nice for that, but I imagine just the 4 cardinal directions would look fine too. Character faces North for any shots between NW to NE, character faces East for any shots between NE to SE, etc.


0

From your question, I understand you need to simulate object occlusion: in real life (as well as in any 3D videogame) you just can't see an object hiding behind another bigger object. I think of an easy way to accomplish this: Use raytracing to detect which areas the player can or can't see from current position (that's what you did in figure 2) to ...


0

The 3D physics and the 2D physics are handled differently in Unity (for example 2D colliders do not collide with 3D colliders). As a result, 3D ray cast will not collide with 2D colliders. However, you can mix and match so you could use a 3D raycast along the z-axis but you will need to attach 3D colliders to your objects. Alternatively, if you want to ...


1

About 15 years ago I was quite satisfied with this algorithm for my Scorched Earth clone in Quick Basic (my first proper game). Generate the landscape from left to right, pixel-column by pixel-column. Start at a random height value between your desired minimum and maximum height and with a random steepness value which is a negative or positive value in ...


0

The trick is to have an a algorithm that produce something that looks good, while depending on random value from a PRNG (pseudo-random number generator, like srand and rand). Then, just seed the generator with the level number and be sure to not use your random number generator for anything else than the terrain. Also, be deterministic: don't depend on ...


0

Make the texture that you want and attach it to the game object you want it to appear on, size it and everything so it looks how you want. Then uncheck its renderer. Then in the code for the game object add public GameObject selectionBox; and then drag and drop the box onto the area in the script of the parent so you have a reference to it. Then in ...


0

Make a texture like this in Paint or Photoshop or something. you can turn this into a sprite and add it as a child of your unit, size it and uncheck spriterenderer then prefab the unit and then add something like this to a OnSelected or OnMouseDown event. SelectedUnit.gameObject.GetComponentInChildren<SpriteRenderer>().enabled=true; there is a bunch ...


0

There is a sweeping algorith for this with logarithmic complexity, precisely (n+k)log(n). The algorithm is described as follows: initialize priority queue = add every endpoint of your lines with priority of x coordinate while queue is not empty, pop one point, depending on type: If it is line segment start point, add to y-sorted-collection and test this ...


0

This is a graph theory problem to determine the outerplanar graph from a random set of vertices. Professors Manuel Bodirsky and Mihyuan Kang of Humboldt University of Berlin considered this question in, Generating outerplanar graphs uniformly at random, 2006. Their work is made available to the public by researchgate here: link to PDF


5

Some more options to consider: Convex Polygons: If you're OK generating only convex polygons, a fairly painless approach is to generate some number of random points and find the convex hull. Example here: http://bl.ocks.org/mbostock/4341699 (Fairly easy to intuit that the fewer points you generate, the less "rounded" the hull will be.) Concave Polygons: ...


2

Just winging it, here's two possible approaches... Constructively Build in such a way that lines cannot intersect. For example, take points spaced evenly alone a circle, and then randomize their radii. Could also randomize their angular position, within their pie wedge. This won't make all possible polygons, the ones it makes will be ...


0

The problem is here: } else if (type.equals("NEXT") && player.getxPos() > SCREEN_WIDTH) { Granted that loadLevel is run at the start of your game, it will run and finish well before player.getxPos() is off the screen width. It will only check once when the level is initially loaded. You need to be able to 'stop' reading the file at 'next', and ...


1

I agree with @Christian (though I wouldn't call it a hack). Detect the condition when the object should look different and then just draw it different. Every single thing in the game doesn't have to be a "model" of how it works in "nature". That's a mistake I've made many times and so it's become something of a mantra for me. Ask yourself this: what ...



Top 50 recent answers are included