Tag Info

Hot answers tagged

5

Without details of your existing algorithm, it's hard to say, but in pretty much any case involving a line over a grid, I've found the answer to be Bresenham's, or a variant thereof. In this case, I'd recommend looking at the Midpoint Circle Algorithm. That can give you a set of outer-bounds tiles, and then just fill it from there.


5

No, there's no way to do this. What you're looking for is a container, that holds references to rectangles that are insides its bounds. This isn't an easy thing to do when you really think about it. There is no way for the rectangle object to know any other rectangle object exists, let alone know if one is inside of it or not. However, there is a few data ...


4

As congusbongus notes in his answer, many games benefit from dividing content into "scenes". A scene might represent a particular level, a room, a minigame, or lots of other possibilities, depending on the game. In such a system, menus can be implemented as scenes as well, and this works well for simple games with only a few menus. Personally, I like to ...


3

Fundamentally I think this is a problem with the grid-based ray casting being a pretty inaccurate and granular approximation of the 'real' thing you're trying to simulate. No matter what you'll do you'll run into problems. Instead of thinking about it in terms of the specifics of the iteration and implementation, think of it as if your world was actually ...


2

The simple approach is just this: Each entity remembers what cells it is in. Each time the entity moves (or rotates or changes size or etc), check whether the cells it is in post-moving are the same as the cells it was in before moving. If the pre-move cells are the same as the post-move cells, do nothing. If there are any differences, update the grid by ...


2

Each cell is a data structure such as a List, or an object containing such a data structure. AFAIK this is not the way how it is usually implemented. This way you will waste lot of memory for arrays or lists, and lot of CPU cycles for manipulating them. For example, 32x32 grid will result in 1024 arrays/lists, and this will be especially bad with ...


2

As was approximately pointed out in comments, the simplest way to do what you're after is to test the center of the square, rather than all of the corners. This isn't exactly equivalent to a majority of the square's area being within your circle, but the latter is a Hard Problem, and it should be close enough for your needs. But note that this doesn't take ...


2

I would keep track of the current direction and reset it every time the box collides with a wall, like so: public float speed; private Vector3 currentDirection = Vector3.zero; void Update() { if (currentDirection.Equals(Vector3.zero)) { Vector3 inputDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); ...


2

The typical way to implement this is using game screens or scenes. Your game loop updates and draws the current screen, whatever that may be Your menu(s) live in one screen or set of screens, your game world lives in another screen Choosing certain menu options (e.g. start game) switches the current screen In this sense, it's just a plain programming ...


2

Let's speak radians. Your angle is clamped to a real range and from what I can see from your video I would say between −π/2 and 3π/2. Now you can also view angles in different ways, for example as points on a circle. This is clearly the intuitive way to see your problem : in your case the tip of your ship is the considered “angle point” on the circle. ...


2

Use GUI Skins. Create a new skin (go to Assets -> Create -> GUI skin), customize it accordingly (you have options for each kind of control), and link it to your script. public class YourScript : MonoBehaviour { public GUISkin Skin; ... public void OnGUI() { GUI.skin = Skin; GUI.Label(new Rect(10,10, 100, 30), ...


2

You could treat the turret as stationary and subtract the velocity of the turret to the target's velocity before the start of the code, provided it works for a motionless turret. To subtract velocity vectors, if the target is moving 4 pixels left and 8 pixels up in a given time, but the turret is moving 4 pixels right and 3 pixels up in the same time, the ...


1

As far as I know, most programs will separate geometry for rendering from geometry for physics. (This is because rendered models can be incredibly detailed, and hit testing against each polygon will take way longer than say, a couple quadtree intersection tests.) If you're using a small number of simple rectangles, you could simply test each rectangle ...


1

I think best way to find inspiration would be to look through android store (if you only want to prectise code and not sell it). Some I can think of: Hundreds Lazors 7x7 Pong Any Pool/Snooker etc Chess Tic Tac Toe Bowman edit: UnBlock Me Tetris? Breakout


1

You need a couple of things here - Something that will randomly spawn things Some way of knowing where sprites already exist so you don't spawn there It looks like you have a handle on the former so I will cover the latter here. For unity sprites you have a component called SpriteRenderer from which you can obtain the size of a sprite: Vector2 size = ...


1

The code has been commented for you. Enjoy. public Sprite sprite1; // Drag your first sprite here public Sprite sprite2; // Drag your second sprite here private SpriteRenderer spriteRenderer; void Start () { spriteRenderer = GetComponent<SpriteRenderer>(); // we are accessing the SpriteRenderer that is attached to the Gameobject if ...


1

You can create an algorithm based of edge intersection. The idea is to draw a line between the two points called a ray. This then acts as a line to test whether the polygons lines intersect. You can do this in pseudo-code: // Method in point: bool IsPointBehindPolygon( testPoint, polygon) { originPoint = this; ray = new Line(originPoint, ...


1

Based on how you explained your movement one simple way of doing it is... Raycast in the direction you move there are only four directions so everytime you move Raycast in the direction you are moving. In your update once the raycast gets within a certain distance say 0.2 unity units.. dont allow movement in that direction and so once the player pushes a ...


1

Your bodies have a current 2d velocity : vcx, vcy. You desire a new velocity: vnx, vny. Correct? Now force translates into acceleration/mass (and velocity indirectly). vnx - vcx = fx/m * t; fx = m*(vnx - vcx)/t So you need to know the duration of time force will be applied. Lets say a frame? Calculate the delta time of the frame. Do the same with axis y. ...



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