# Tag Info

17

There are two ways an AI controlled unit with a bound rotation speed and an adjustable movement speed could reach a goal. First, lets consider the challenge we are presented with so we could understand it better: If the player is moving and rotating in constant speeds while trying to reach a goal that is on its right or left side, it will move in circles ...

15

Give your agents a weak "electrostatic charge" to make them repel each other, along the lines of Coulomb's law. Assuming for simplicity that mobs should push each other away with equivalent strength, it should be enough to apply a force between every pair of mobs with a magnitude some_constant / distance^2, where some_constant is a configurable repulsion ...

14

Let each wall exert an influence on the velocity. Try something like using the inverse distance (or inverse squared distance) from the wall to determine the magnitude of the force that each wall "exerts", and the normal of the wall to determine the direction of the force that the wall "exerts". So here the boid interacts with 4 walls. Since the dot ...

8

What you have to do is estimate the future position of the moving target and steer towards that. Here is bobobobo's super 5 step simplified process 1. Initial picture of the system. 2. Really what we are doing here is subtracting the rocket's velocity from both bodies in the system, so the rocket is effectively "stationary", and the target is moving 3. ...

8

If someone needs the code, here it is, feel free to redistribute it. I've tried to comment it to be more understandable. Based on bobobobo's solution. Vector2D ReynoldsSteeringModel::repulsionFromWalls(vector<Vector2D *> walls) { Vector2D force; // My force will be stored here Point2D pos = self()->position(); // Position of the agent /...

7

One solution would be to cheat a bit and guess what the player wants to do. When the player is on a straight section and presses left, you can assume that he wants to switch lanes. When he is close to a curve or intersection, he certainly wants to turn. The player is unable to control it's exact steering angle in a curve, so you could decide to give the ...

5

Just clip the maximum allowable rotation angle of the heading vector for the agent to something like 5 degrees/frame. (ie the red vector in your diagrams). Right now your agents kind of have this omnidirectional capability to steer. You need to change that. To get the agent to behave more like a car, an agent should only be able accelerate in the FORWARD ...

5

It looks like the problem is that the missile is simply pointing itself at the target without regard for it's current velocity. Assign your missile a maximum angle by which the thrust can deviate from the line of motion. At each guidance iteration you calculate it's velocity perpendicular to the target. Figure out how much it must tip it's engine in order ...

5

I'm going to assume that the rotation of the engine is purely visual, and the acceleration during any thrust is in a constant direction. (If we're accelerating in a rotating direction, the math for planning the trajectory gets a LOT more complicated very quickly, so I'd recommend turning off the thruster when turning, and just accounting for that as a linear ...

4

It may not be the elegant solution you are after, but I've found that if I slow the missile, if it's going to miss, as it approaches the target, it effectively tracks and turns quicker and can hit the target. You could increase the turn rate of the missile as it gets closer, rather than reducing the speed, but this might give players a 'wow I'm sure that was ...

4

Intuition Here's one way: Let's rotate your diagram. Now the rocket is a cannonball! Physics It has a fixed acceleration "downwards" i.e. perpendicular to the vector from its firing location to its target. I drew it above as a dashed green line. Let's call that the reference horizon. (Note that this reference horizon is constant! The rocket was fired ...

4

Since your AI is steering based it's pretty simple. You need to weigh your forces based on how important they are. The closer you get to obstacles the more important they should be, otherwise chasing should be the most important. There are a couple different ways to implement it, but I always found having some "max force" worked best where you iterate over ...

4

This is a pretty interesting question, and i'm going to try to contribute with what I can. First, I think you have to clearly define the boundaries for the game you are trying to create, and define those questions (some may already been answered). How far the is the monster aggro ? How many monsters at the same time is your target? How is your terrain ...

4

Instead of laying your approach vector on the line connecting the target to the current position, lay it along one of the tangents to the desired orbit from the current position. Than make just a speed change at the point of tangency. This is actually quite similar to how real orbital mechanics is performed, so should feel quite natural in addition to being ...

3

As a mechanical engineer whose also interested in game development I appreciate how difficult this problem can become; anything more than the naive solution I am about to describe requires a sound understanding of control systems. Simple Solution I am developing a 2d game where players have control over a spaceship (approach should work just as well for AI ...

3

The easiest way to do this seems to be to simply generate a random point on the mesh and walk to it. You can restrict the point to be within a radius of the monster's position in order to avoid really long random walks too.

3

Add all the relevant forces together. Clamp them at the end to a maximum acceleration rate for that agent. Then you're done.

3

I'm sure your steering code is fine, however there are some values you need to change to get it to work properly. There are a few factors to steering that need to be accounted for to successfully stop the first time. If your mass is too high or your acceleration is too low the object will oscillate. The object won't have the power it needs to stop its self ...

3

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 ...

3

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; ...

3

While a bit different to your example above, I have implemented a spring algorithm into my game that has worked for me. The idea is that if the object comes close at a certain determined buffer distance to another object, a magic invisible spring appears and corrects the path of the object(s). Here is a video recording of my game engine demonstration ...

3

Yes, we can do better. We need a maximun steering per unit of time. // get the steering direction steering = desired_velocity - velocity // ensure the steering never exceeds our maximum steering per unit of time steering = truncate(steering, max_steering * delta_time) // ensure the velocity never exceeds the max speed velocity = truncate (velocity + ...

2

Effort will be specific to your simulation. You could do something like the sum of the distance each agent traveled. Or the sum of all the direction changes each agent had to make. It depends on what your definition of fitness is. For either of the two above, you can just keep a running total for each agent, then add them all up, just as you do for distance:...

2

As Byte56 mentioned in the comments use path finding. If you only want to get the closest enemy then use breadth first search, preferably with limited depth, and use the first encountered enemy as your target. Also, as Byte already mentioned, you will need waypoints for your steering, you can't just start steering towards the enemy position as the path to ...

2

This comes up in AI fairly often. I think what you are looking for is a way to keep your State Machine organized. Assuming you are using an object-oriented language, the general idea is to represent each of those actions that your agent can do as a state Object, with a defined entry and exit methods that leads into other states. You're most likely going to ...

2

if (degrees < 45 && degrees > -45) direction = vector(1.0, 0.0); else if (degrees == 45.f) direction = vector(1.0, 1.0); else if (degrees > 45 && degrees < 135) direction = vector(0.0, 1.0); else if (degrees == 135.f) direction = vector(-1.0, 1.0); ...

2

That function gives you a direction scaled such that it indeed performs an instantaneous velocity fix, if added to your velocity. You can think of this as the "steer direction". You can scale this direction by whatever factor you like. Maybe something like this to get started: const dt = (1.0 / 60.0); object.velocity += dt * object.Seek( targetPosition ); ...

2

One good solution is to send 2 rays from the upper and lower bound of the object rather then in the middle. You can then use the algorithm you were using before but use collisions for both rays rather then one. Don't forget to set the direction to the correct value of only one ray hits something (that is away from that ray). If both rays hit an object just ...

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