New answers tagged

1

Cameras are very sensible to anything that does not move them perfectly smoothly. The camera should be updated in an Update or LateUpdate. One way to handle cameras is to adjust variables in a FixedUpdate, and to move the camera in the (Late)Update based on the given variables. Moving the player in a FixedUpdate with the camera being parented to will cause ...


0

In the top right (I believe that is the default), there is a section called transformation. You can change those numbers to all 0. I believe there is also an option to 'reset' as well in the transform section.


1

Select an object you want to center your view on and press the F key to snap your scene view camera to that object, zoomed to fit it in view. "Frame Selected" is the name of this shortcut.


1

What I’m describing was caused by the Rigidbody2D auto-calculate mass. Just uncheck that box and it should work fine!


0

You can possibly achieve tile animation by using unity's "AnimatedTile" Script which comes with the 2d-Extra repo. This video from unity discusses how to use the AnimatedTile Script. I hope it helps. https://github.com/Unity-Technologies/2d-extras/tree/4eff73f468142907629f09b4a88bceb2f0148dc5/Runtime/Tiles/AnimatedTile


1

This is what I figured out and it works, but Martin's answer is probably a lot more efficient. I went ahead and used the array of y values that I made, and then below it made a bunch of code segments like this: for (int i = 0; i < yValues.length; i++) { if (sprite.getY() == yValues[i]) { g2d.drawImage(sprite.getImage(), sprite.getX(), ...


1

The problem was caused by manual replacing of .png picture in project's folder. At first time I didn't found a valid way to import an image as sprite, so I created a default one in Unity, which creates a sprite and a picture 1x1 pixels. Then I replaced it with my own picture, but metadata didn't change, and the Unity still worked with sprite like it is still ...


-2

Old graphics have to be in powers of two. New graphics have a split. If the file is in the DirectDraw Surface format, then images need to be in multiples of four, otherwise images needs to be in multiples of eight. Therefore, for portability, images needs to be multiples of eight. Note that it is the sprite sheet that needs to have multiples of eight in ...


1

Generally it's up to you. Think about it in a abstract way. Read some articles and extract the ideas. Give it some time and gather the experiences. Imagine that games have something like GameObjects(player, enemy, bonus, wall, trap, weapon, etc.) Each such a object have some properties and methods like position, rotation, moveTo, scaleUp, etc. Those ...


1

instead of trying to identify the drawing order for each sprite itself you should create a proper drawing order first of. List<Sprite> sprites; Comparator<Sprite> topLeftComparator; void draw(Graphics graphics){ sprites.sort(topLeftComparator); //create proper drawing order first for (Sprite sprite: sprites){ sprite.draw(...


1

The simplest implementation is for your Tile class to have two members: visible and opaque. Optionally, but a very useful third member is solid. visible: Is the tile currently visible by line of sight to the player? opaque: Does this tile block visibility of the tiles behind it? solid: Does this tile block movement? If a tile is not visible it should not ...


0

Waited more than I expected. I found a simple solution for this. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 direction = new Vector2(mousePos.x - transform.position.x, mousePos.y - transform.position.y ); transform.up = direction;


1

You just have to make the other characters do exactly the same things the player-character does, but with a delay. So you have to create a script which records the actions of the player and then allows to retrieve the player's position X steps ago. The C# standard already has the ideal data-structure for that, the Queue. It allows you to create a first-in-...


1

this is how I solved this issue for myself. I hope it helps , ) In the frag shader the important bits are. . . vec2 rotate(vec2 v, float a) { float s = sin(a); float c = cos(a); mat2 m = mat2(c, -s, s, c); return m * v; } void main() { .... .... //The delta position of light vec3 LightDir = vec3(LightPos.xy - (...


0

To detect collisions between a circle and an AABB, you should find the closest point from the AABB to the circle. You can run the below code snippet and try to move the purple point which represents the AABB center to watch the position of the closest point. <iframe src="https://www.desmos.com/calculator/u32th8uhli?embed" width="500px" height="500px" ...


1

I managed to solve collisions problem by splitting the collision handling into horizontal and vertical components, one at a time. The implemented idea is: Move player on horizontal axis. Check for collisions. Solve collision on horizontal axis. Move player on vertical axis. Check for collisions. Solve collisions on vertical axis. This system does not ...


1

I'm on my phone and can't provide a super detailed answer, but here goes. This answer will not cover the physics calculation that you use, only the logic. It looks like there is trash data in your loop. When evaluating a body with itself, you do not update the angle and the acceleration, it remeains to what was used with a previous body. Whatever is in ...


0

Globally uniform chunk boundaries Resolving those chunk edge discrepancies can be done without interpolation. I would suggest using a global function (e.g. 2D Perlin) to define chunk edge heights, so that all chunk edges (at least) align. This is basically like having a series of empty buckets with each neighbour pair of bucket sides having matching heights:...


0

I would define a class for each type of room shape. For rooms that are quadrilaterals or circles, it is easy to define those shapes and test if a given point is within them. If the shapes of your rooms are anything else, it may be easier to create a Polygon Collider and test Collider2D.OverlapPoint using that collider and the position of the unit: public ...


Top 50 recent answers are included