Hot answers tagged

4

Your problem lies in generating the graph, before any actual pathfinding takes place. It looks like you want the intersections of tiles to be considered the nodes of your graph, and only want intersections where all four adjacent tiles are ground. If you do it correctly, the pathfinder in your example will have only one valid path to choose from.


3

If I understand correctly, you want the algorithm to return a path that touches the center of each grid (the red dots, in your last image) rather than one that goes along the grid lines (the blue line, in your last image). To accomplish this, you need only to add the half-size of your node to the node's world position. For example: Given a node whose grid ...


3

An EdgeCollider2D would handle this case well. Much like a LineRenderer, you provide it a list of points to join into line segments, marking your collision boundary. It can be a closed shape, but it is not required to be closed.


2

You'll track two separate position variables here: your current on-path position, and your current actual position, shifted from the path. Store your offset from the start of the path when you first begin traversing: waypoint_index = 0; path_position = path.get_waypoint(waypoint_index); offset = actual_position - path_position; When you update your path ...


2

So after much effort I finally get it working, although I'm not sure if I did it the best way. Tried to do what Agent Tatsu suggested but it didn't work. I did something based on what I understood from the BlueRaja's answer. Basically I took every walkable tile of the map and "packed" each with its three adjacent tiles to form a "bigger tile". Each of these ...


2

This problem is just begging for Newton approximation like recursions. How to find distance of arc up to precision required? First iteration: Find out the distance between both endpoints. Create new points at 1/4 of a distance from 1/4 first control point to 3/4 of second control point, plus 3/4 of a distance from 1st point, plus 1/2 the distance. Measure ...


2

Set the pickup to be on a layer that interacts with the ground only, not the player character. Give your player character a child object that represents their collection radius. Give it a trigger collider, and set just this child object to be on a layer that interacts with the pickups, leaving the root of your player character on its original layer. Now your ...


2

Interestingly, if the player dies before reaching any checkpoint, the MoveTowardsPlayer scripts still works after respawning. It only stops working after any of the checkpoints are reached. Presumably your problem code is this: if (dist < sightDistance) theRB.velocity = targetDir * moveSpeed; When you respawn the enemy, you move it back to its original ...


2

First disable the gravity of the objects rigidbody when it gets spawned. You can do that in the inspector of the prefab for your projectile, or you can do it with code. For a 3D rigidbody you do that with: GetComponent<Rigidbody>().useGravity = false; For a 2D rigidbody you do that with: GetComponent<Rigidbody2D>().gravityScale = 0f; When the ...


1

Before Trowing object just disable the gravity of the object and upon reaching to the destination or by reaching the velocity of the object to 0 or nearly 0 then reenable object gravity so that object falls down freely. I hope this will achieve the required effect. (Converting comments to an answer so that next person in need can find it easy). Thanks to @...


1

Thanks to DM Gregory's comment, I have understood and solved the issue. Since I am using the Head object in animator, the sprite is updated in every frame. Therefore, even I change it in one frame, it goes back to default in the next one. This is the right way to do it: public class PlayerHead : MonoBehaviour { public static PlayerHead instance; ...


1

In your OnCollisionEnter2D() function, you have this line of code: enemy.Hurt(); You don't set the value of enemy anywhere in that function. It's likely that enemy is always pointed at the same enemy, so each time you call Hurt() it's actually on the same enemy (not necessarily the one you collided with) and thus Hurt() is getting called on the same enemy ...


1

So I found out the answer thanks to Zibelas! I forgot to apply moveVector to my movement. //Move the player myBody.velocity = moveVector * moveSpeed;


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