Tag Info

New answers tagged

1

I solved the problem. Now script work fine. Just drop this script on game object and enjoy. using UnityEngine; public class UnitWander : MonoBehaviour { public float CircleRadius = 1; public float TurnChance = 0.05f; public float MaxRadius = 5; public float Mass = 15; public float MaxSpeed = 3; public float MaxForce = 15; ...


2

There is no 'best' solution to this problem. Ultimately you're going to have to find by trial and error something that gives the best tradeoff between performance and believable intelligence. However if you want to use any sort of path finding algorithm you're going to need to subdivide your world in some way. Whether you go with tiles, polygonal zoning or ...


0

The way I have done it in the past is with A*, but tweaked. Calculate the A* path, but remove the last n waypoints from the path. Then when that point is reached, recalculate. Only remove the last n waypoints if there are at lease n+m waypoints. Otherwise, send to target, and recalculate. Once there is only one way point, the calculation is minimal. This ...


1

You should take a look at some vector math stuff, here's an example of a Vector class that will help you quite a bit in implementing this sort of logic. I think this is without bugs, but who knows. class Vector: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Vector(self.x + other.x, self.y + ...


17

I haven't looked at specific implementation of A* by Aaron but with a normal A* you could include the 'block tower' as passable terrain but update the heuristic so that the 'cost' is much higher than a normal tile (so that AI will evaluate whether it is easier to destroy the block and continue or simple go around via the path that is not blocked). Then you ...


0

If what you are looking for is a sort of taunting tower you can add a collider to it set as is trigger and when the minions enter the trigger they are just scripted to attack the tower. If you want the minions to attack the towers only when there aren't alternative paths, then when the path is blocked and the A* is called to calculate another path if it ...


0

Pick a random point on the map which is not blocked. Then Calculate a path from the current position to the destination using a stock route finding algorithm like Dijkstra's Algorithm or A*. When no route can be found, then the random destination is either unreachable. Pick another point in that case. To avoid a deadlock in case there is no possible move ...


1

You may be interested in Nodal Pathfinding. The concept is similar to placing waypoints, except you generate these way points on top of your world. The waypoints are then used with an A* pathfinder, to determine the optimal path. Have a look at the blog here: http://www.jgallant.com/nodal-pathfinding-in-unity-2d-with-a-in-non-grid-based-games/ Another ...


1

Use waypoints in your map. The enemy AI in "patrol" state chose a random visible waypoint as target. Reached the waypoint repeat step 1. (eventualy excluding current waypoint) If you don't want to place manualy waypoints you can generate them at the corners via script : here follow an example: cons: the enemy will patrol in straight lines from ...


1

Hey there are couple of things which you are missing out. 1) Even thought the motion is in 2d plane but the gameobject dimension is 3D, so use Vector3 instead of Vector2 2) When you calculate Vector3 Movetowards it returns a value which is calculated upon current position , target position and speed. This needs to be assigned to the transform of the AI. ...


0

Your targetX and targetY are being set as your current script's transform.position, rather than your target's position. Also, targetX and targetY are Transforms, when really it sounds like they should be floats, or perhaps even just simplified as a single var target : Transform;. You could also just have var me : Transform; as well. Your MoveTowards should ...


1

As Vector2 is a type composed by two numbers which are x and y, then you should be able to get the position by asking both numbers: Vector2 YourVar; YourVar.x; YourVar.y; So you should use something like: SetPositionToMove(YourVar.x,YourVar.y); //if the functions expect x and y or: SetPositionToMove(Point2(YourVar.x,YourVar.y)); //if it expects a ...


1

Refactoring is your friend !!! Separate the issues and try to get your code as generic as possible. Separate and factorise the steps of the computing. Keep comments short. • Boilerplate : // ------------------------ var g = 9.81; //Gravitational acceleration var v = 35.9; //Experimantally measured arrow speed var sqrt = Math.sqrt, atan2 = ...


2

I assume you know the basic maths stuff concerning angles, movement, distance and all the other stuff. You have these goals: reach destination do random stuff stay inside (rectangular?) area of playfield Your plane could have these properties: position pos forward-speed vel forward-acceleration acc heading/rotation in degrees rot angular velocity ...


1

The most simple solution must be to randomize path points. Each point can only be within a certain angle from the previous ones. After x points have been created, change the angle setting to make it steer towards the destination. Something like this: Vector2 currPos = plane.pos; Vector2 currDir = plane.startDir; for(int num = 0; num < MaxPoints; ...



Top 50 recent answers are included