Code Monkey home page Code Monkey logo

unitysteer's Introduction

UnitySteer 3.1

Build Status

General notes

UnitySteer is a toolkit to help build steering behaviors for autonomous agents in Unity. Initially based on OpenSteer, UnitySteer has been significantly reworked since it was first translated - the concepts and some of the code remain the same, but it follows a more Unity-like component-oriented philosophy.

Please read License.txt before using in your projects. It's short, sweet and to the point.

Main repository

If you have obtained this library from a third party, you can always find the latest version on Github.

Tutorials and examples

Looking for a UnitySteer tutorial? The UnitySteer Examples repository contains a series of examples and experimentation notes for you to teach yourself the library basics and how to compose your own agents.

Dependencies

UnitySteer uses TickedPriorityQueue. The latest library is now included on this repository.

UnitySteer 3.1 requires Unity 5.x for 2D support. The last version to support Unity 4.x was UnitySteer 3.0.

Stable and beta versions

The current stable release is UnitySteer 3.0 RC2. It contains a significant number of improvements and fixes over 2.7, but it also introduced several breaking changes, so make sure you catch up with the latest UnitySteer blogposts, as well as reading the changelog.

I develop UnitySteer following git-flow, so if you're looking for a specific version, you can look at the project tags:

UnitySteer and iOS

If you are using UnitySteer on iOS, bear in mind that you may need to search for and change any LINQ calls, since Unity has a penchant for not AOT'ing them properly.

unitysteer's People

Contributors

alan-fgr avatar capnslipp avatar gandag avatar philippe-dasilva avatar pjohalloran avatar ricardojmendez avatar richard-fine avatar sebastianludwig avatar simie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unitysteer's Issues

How would you use UnitySteer for guided missiles

Hi,

I've been using UnitySteer for quite a while now, and I'm getting some issues using it for my missiles.
So before I totally change my mind and implement some simpler predictive steering behavior, I wanted to ask for help.

So this isn't a bug nor a feature request but a real quest for help ;)

I created a simple sphere gameobject which will act as my guided missile.
I attached to it an Autonomous agent, a Spherical collider and a SteerForPursuit component.
I then simply set the target to the SteerForPursuit behavior and implemented a simple Missile class which would capture the OnTriggerEvent to apply damages, explosions and all the fancy stuff.

Now, what happens is that the Pursuit isn't suited for that as it'll use the Arrival radius of the target agent and I may use it for something else.
Moreover, if I set the Arrival radius to 0, the missile actually goes through the target but the TriggerEnter event is never raised and I don't get why...

Thanks in advance.

Document Steering.Weight on editor

Steering.Weight is well documented on the code, but perhaps a small in-editor note would make its use clearer.

I could just rename it to "Strength", but it's a bit late in the game for such a breaking change.

Velocity being smoothed on calculation, not on application

Commit 485e3f3 introduced a change where we split the calculation of a vehicle's velocity from its speed.

While the vehicles still applied acceleration smoothing, they applied it to the result of the force calculation. However, force calculations don't necessarily take place every frame, whereas force application does. It would make more sense - and yield smoother behavior - to perform this force smoothing on when the force is applied to the vehicle, since otherwise the speed being applied still changes in steps based on the last calculation.

Clean-up changelog

Consider removing the old 2.x notes from the changelog on final 3.0 release - they're cluttering it and not adding much recent actionable information.

NullReferenceException in Steering.cs

I was getting a NullReferenceException error in SteerToFollow.cs because I hadn't instantiated a Vehicle when trying to call CalculateForce() in SteerToFollow.cs, which of course inherits from Steering.cs.

protected override Vector3 CalculateForce() {
//Debug.Log(Vehicle); // Was returning null
return Vehicle.GetSeekVector(Target.position, _considerVelocity); //Thus this didn't work then obviously
}

I went over into Steering.cs and changed the Vehicle GET property to the following and it finally worked:

// Cached vehicle
Vehicle _vehicle;
public Vehicle Vehicle {
    get { return _vehicle == null ? this.GetComponent<Vehicle>() : _vehicle; }
}

I've really studied your code and I'm not sure why calling the base to Start, and I even tried calling the base to Awake, didn't find the component before CalculateForce tried asking for it. I imagine I'll have this same problem if in the other behaviors. Any ideas? And can you reproduce this error?

Release UnitySteer 3.0f1

UnitySteer has been at RC3 and stable for quite a bit. With the latest commit to support Unity 5, I think we're good to go on a final release.

iPhone compatibility

Has anyone successfully implemented UnitySteer into a Unity iPhone project?

During launch the project crashes due at a:
System_Runtime_Serialization_SerializationInfo_GetValue_string_System_Type

with the thread also containing a System_OutOfMemoryException__ctor_string

oddly enough it launches if the following Unity build settings are enabled:

  • Development Build
  • Script debugging

I'm assuming this is due to something going on in the c5.dll?

Threaded Ticked Queue

Hi,

I am wondering: would run the queue in a dedicated thread make sense? It doesn't directly apply modifications to transforms or GameObject, right?
I'd like to run a lot of AutonomousVehicle on mobile, several hundreds at least. so I am wondering on possible ways to make it happen.
I noticed with a couple of hundreds just the queue update will take something between 25-40ms to run on my Android device. Plus the rest, I am far from 30fps.

Cheers.

Objects spinning

Our project is being developed in space and uses X/Y/Z movements. I have noticed on some of our models that when it is heading in the Y (+/-) direction, it does a deathroll (like what an alligator does). I have tried to work it out of the system but cannot figure out why it does it.

I am using the autonomous vehicle script and giving them the steer to wander + the other typical stuff, and then I attach them to a point.

Help with SteerForPathSimplified !!!

Hi everybody,
This is the first time I am using unitysteer, i tried to use SteerForPathSimplified.cs but the problem that i wasnt able to assign the path to the script.
Can anyone help me with this?

Code Docs with tutorial

While the examples are a nice start a full documentation with a tutorial for first time users is sorely needed.

Automated deployment

While this wouldn't actually buld per se (though if it is actually possible distributing a dll is way better than a unity package with source code) some sort of continuous integration or at least automated deployment would be a huge help. (it would also help with the future docs)

Consider unifying queue settings

We currently have queue settings on a per-agent basis. It seems like this would make more sense configured globally, or at least per agent class with a central queue settings manager.

Might be overkill for now, but making a note of it for the future in case anybody has comments.

About UnitySteer and Physics

Introduction:
First of all: Thank you so much for UnitySteer! It is great!

I'm working on a 2D Physics-based game with zero gravity (in space);
My game will use Steering Behaviors heavily!

Issue:
But I noticed that UnitySteer's Autonomous Vehicles conflict a little bit with Unity's Physics.

If I try to apply other forces externally (via some attached script for example), the Vehicle behaves strangely or the forces do not even apply.

This is most notable by the lack of Inertia.
Since my game is in Space, this is really distracting.

Sometimes something collides with an Autonomous Vehicle and there's no Inertia from the Collision.

I also did an experiment where I would control an Autonomous Vehicle GameObject using WASD for Physics-Based movement:

  • With the Autonomous Vehicle Component off: Inertia works just fine.
  • With the Autonomous Vehicle Component on: Only torque/rotational inertia would work.

Can you help me?
Can you help me understand better the relationship between UnitySteer and Unity's Physics?
Can you help me fix those mentioned issues?

Thank you for your time!

UnitySteer and A* pathfinding

Hi,
I'm working on my master thesis in Computer Engineering in which I have to simulate a realistic crowd in a city.
I'm using UnitySteer with A* Pathfinding (by Aron Granberg), so I created a script similar to SteerForPathSimplified that use a path built with A*.
In my scene I have many capsules (agents) which have attached also SteerForNeighbourGroup and SteerForSeparation to avoid themselves (and it works), but if I add an obstacle (with DetectableObject attached) my agents try to avoid the obstacle and not themselves anymore.
Why is this happening?
Also I have another question: Can I add or remove different streering at runtime (since I need to change the agents' behaviour: for example, initially they are walking through the path, but when it starts a fire they should run away - like SteerForFear helps to do it -)?.

Thank you!

Errors during Installation

I downloaded the sample zip file. I extracted it to a directory under my Unity3D version 3 folder. I downloaded the UnitySteer zip file and extracted its contents to the Assets/Scripts folder.

I start Unity3D and select that sample project. I get errors like, "Unable to create metadata directory" or "Unable to create cache directory". So I created these subdirectories manually under the Library folder. Then the sample worked.

Cannot set the velocity directly on PassiveVehicle

Hi :)
There is a small mistake/incoherence in PassiveVehicle.cs.
The Velocity property setter is defined to throw an exception if we attempt to modify the property. But I set that my vehicle cannot move and in the Update method it is stated if the vehicle cannot move then Velocity equal Vector3.zero. So each Update it is throwing an exception.
Anyway great port of OpenSteer.
Thanks.

RC2 Release

Release UnitySteer 3.0 RC2 with the latest bugfixes.

Speed of SteerForEvasion

When my agents are evading a menace, I noticed that they ran slower when they were closer to the agent, and faster when they were further away, until they reached the safetydistance, then stopped evading abruptly. Should this be reversed, so they evade faster when they are closer? I think I have some code worked out to do this.

Also, I think the distance calculation uses the current position of the menace in the safetyDistance calculation, not the predicted position. Is this for efficiency?

Feature request: Update instances during runtime on prefab changes

Thanks a lot for sharing this!

It would be great to be able to change properties in the prefab during runtime and have these changes updated to the instances. Being able to see the changes instantly would make it really easy to fine-tune the whole system.

Thanks!

Cannot put Package in subfolder

Qhen I try to put the UnitySteer folder inside a subfolder in Unity The autonomousVehicle stop working. Is this a known isse? or I'm doing something wrong?

Thanks

Basic vs Post-Processing behaviors

First all, thank you so much for making + sharing UnitySteer!

I have question between Basic & Post-Processing behaviors, is Post-Processing behavior design to overwrite the Basic one?
In the funciont CalculateForces() of TickedVehicle.cs, the adjustedVelocity will overwrite newVelocity to be the TargetSpeed. So I'm just curious about the intention, and wondering if you have any tips to find the balance between different behaviors, or any resources about learning the theory. Thanks!

Strange behavior on Evasion when target doesn't move

Hi Ricardo,

It's me again :P

I have a bizarre behavior with the steerforevasion component when the target isn't moving at all: they kinda flee like fishes :p while I would expect a straight movement instead.
I've posted a small video on Youtube to illustrate that. Note that this is valid for all instances I used.

https://youtu.be/2x-lP3VzXZ0

Thanks for letting me know if you see what I could do to remove this behavior.

Change SteerForNeighbor organization

Currently the SteerForNeighbor behaviors, such as SteerForCohesion, SteerForSeparation and SteerForAlignment, all come from a base class on which CalculateForce iterates over the detected vehicles, checks if they're still valid, and verifies that the vehicle is in the neighborhood before adding up its contribution.

This has the advantage that we can configure some values such as the angleCos on a per-behavior basis, but the disadvantage that we're evaluating some values and iterating over the list multiple times, when one could suffice.

I'll update it so that:

  • Each SteerForNeighbor behavior exposes CalculateNeighborContribution.
  • SteerForNeighbor itself will always return Vector3.Zero for its own force, and will not have the current radius and layer checking configuration properties.
  • A new SteerForNeighborGroup will aggregate all existing SteerForNeighbor behaviors, and iterate over the neighbor list only once, calling the relevant methods on each.

This will likely make a difference mostly on larger clusters.

2D integration issues

Hello. I am planning on using UnitySteer as my primary pathing system for a 2D space shooter, specifically using Unity5 2D. Some issues I had to deal with, for future reference:

All rigid bodies and colliders use the 3D version only, not the 2D version (Rigidbody vs Rigidbody2d, Collider vs Collider2D). Had to go through and replace them, would be useful if this was an option.

Had to change the forward vector to up by default, since thats the Unity default. Theres a pending pull request that handles this well, as well as locking rotation axes.

All behaviours are assumed to be on the gameObject on awake. This makes swapping steer behaviours out dynamically impossible withough having a pile of disabled steers cluttering up the prefabs. Minor issue.

Additionally, modified the radars to store rigidbody ids instead of collider ids, but thats very specific to my game. Very simple to do.

MapPointToPathDistance seems wrong

Specifically this part:
https://github.com/ricardojmendez/UnitySteer/blob/development/Vector3Pathway.cs#L205-L208

We add the whole segment length even if we are only part way along this segment
segmentProjection is a fraction (0-1) along the length of the segment, so we need to multiply it by this segments length.

I think this is what it should look like:

if (d < minDistance) {
    minDistance = d;
    pathDistance = segmentLengthTotal + segmentLength * segmentProjection;
}

segmentLengthTotal += segmentLength;

TickedVehicle and DesiredVelocity setting

I'm using UnitySteer in some crowd simulations. On my TickedVehicle, I have set CanMove to false, and want to use the DesiredVelocity in another script to run a mecanim animation, but have run into a few problems and questions.

In CalculateForces for TickedVehicle, I noticed that when CanMove is false, nothing is calculated, because of the if statement in line 150. Also, the DesiredVelocity does not take into account the possible corrections found in postprocessing in lines 219-234, like from SteerForNavmesh.

A related question; when postprocessing velocity is nonzero, should it be smoothly interpolated into the previously calculated velocity? Right now, when the agents leave the NavMesh, their velocity spikes up to MaxForce and does not look smooth.

_speed at null

Hi,

using unitySteer for my project (lots of bugs running in a scene), I had some troubles with this version (used an older one, but I really need this optimized one).

If the speed of the vehicle is null at first, when we calculate the Velocity :
return Transform.forward * _speed; (line 34)

we get a NaN;

So I changed the _speed from the initialization in the code (line 14), this is probably not the best solution, and I think I have this error due to a bad usage of your class. But this works for me.
Is there a better way to do this ?

Cohesion Behavior doesn't take position of boid being steered into account?

Hi!

First thing I tried after opening the boids example was reducing it to two birds who only had Cohesion Behaviors. I then made the Cohesion Behaviors aware of everything within 180 degrees and radius of 20.

Strangely, the birds consistently behaved badly. One would head for the edge of the screen and the other would follow (based on the initial positions).

So I looked, and when the center of the boid 'flock' is found in the Cohesion Behavior, it is found in global space rather than 'current boid relative space'. That means that the forces being generated were only proper if the current boid being steered happened to be at the origin.

When I fixed this, the boids continually 'seeked' each other as I was expecting.

Bug or feature?

SphericalAvoidance problem

I've used your examples in test cases folder and noone works with spherical repulsion. I'm trying to set up a biped with steerforpoint and avoid obstacles. Any guess?

FindClosestEdge in SteerForNavmesh

I couldn't seem to ever end up in the else block in lines 164-170 in SteerForNavmesh, even when my agents were far away from the Navmesh. They would return very far away edges and try to navigate to them incorrectly. I think this is due to the use of the same NavMeshHit object in both lines 150 and 155. If I create a new NavMeshHit object for use in line 155, then it hits the else block when it should.

Follow/Align while Orbiting Another GameObject

Introduction:
First of all: Thank you so much for UnitySteer! It is great!

I'm working on a 2D Physics-based game with zero gravity (in space);
My game will use Steering Behaviours heavily!

Context:
In my game you control Ships by touching on a Tablet;
You touch and then the Ships follow your finger.
I have such behaviour working just fine.

Issue:
However, there's a Ship which Orbits around another GameObject with Input;
I have the Orbiting behavior working just fine;
However I only know how to make such behaviour by using key presses
(To tell the Ship to go Clock-Wise or Counter-Clockwise);

The Player should be able to touch, and have the Ship Orbit around another GameObject
trying to Steer to Follow and/or Allign with your Finger; Without breaking from her Orbit pattern;

image

image

image

The Ship will always try to Align as much as possible with your finger:
image

Or Arrive at/Follow the Location of your finger:
image

Can you Please Help Me?
How one achieves such complicated steering behaviour using UnitySteer?!

Thank you so much for your time!

Feature request: prevent SteerForPath skipping waypoints

Hi, current implementation of SteerForPathSimplified2D uses closest way-point to the vehicle and could skip some points. This happens for complicated paths, for example, with loops.
What do you think about adding a flag to SteerForPathSimplified2D (or different SteerForPathBehavior) that will force vehicle to visit every way-point from array in straight order?

Thanks.

Ticked Vehicle's newVelocity and newAcceleration

Thanks for the great tool!

I am using TickedVehicles and SteerForPursuit. I have been trying to figure out how to get rid of the deceleration of the ticked vehicle as it gets closer to the target. I would prefer it kept a constant speed and rammed into the target. (Maybe I should be using SteerForSpeed in addition to the SteerForPursuit?)

When I was looking at the code in TickedVehicle, I didn't understand what was happening with the newVelocity and newAcceleration variables in the CalculateForces() method. (I have pasted here.)

            Vector3 newAcceleration = (clippedForce / Mass);

    if (newAcceleration.sqrMagnitude == 0)
    {
        ZeroVelocity();
        DesiredVelocity = Vector3.zero;
    }

    /*
        Damp out abrupt changes and oscillations in steering acceleration
        (rate is proportional to time step, then clipped into useful range)

        The lower the smoothRate parameter, the more noise there is
        likely to be in the movement.
    */

    if (_accelerationSmoothRate > 0)
    {
        _smoothedAcceleration = OpenSteerUtility.blendIntoAccumulator(_accelerationSmoothRate,
                                    newAcceleration,
                                    _smoothedAcceleration);
    }
    else
    {
        _smoothedAcceleration = newAcceleration;
    }

    // Euler integrate (per call time) acceleration into velocity

    var newVelocity = Velocity + _smoothedAcceleration * elapsedTime;

    // Enforce speed limit
    newVelocity = Vector3.ClampMagnitude(newAcceleration, MaxSpeed);
    DesiredVelocity = newVelocity;

It appears that newVelocity is declared and assigned to _smoothedAcceleration * elapseTime. But then when we enforce the speed limit we just write over the value that was just assigned.

At first I thought the this:

newVelocity = Vector3.ClampMagnitude(newAcceleration, MaxSpeed);

...Needed to be changed to this:

newVelocity = Vector3.ClampMagnitude(newVelocity, MaxSpeed);

But then I realized that I am probably just confused. Any clarification of what is happening there would be awesome.

Thanks!

Support for 2D projects

I've tried UnitySteer for 2D project, but even with AllowedMovementAxes setting, the sprites rotate around all axes which breaks the sprite orientation.

From my poking around it seems that few changes could make UnitySteer support 2D movement:

  • Allow setting custom "forward" vector
    • Public property for forward in vehicle ( default Vector3.forward for BC compatibility )
    • All uses of Transform.forward would instead use that property in calculation ( rotation * Forward )
    • Not sure Vector3.Slerp will not break rotation for 2D during AdjustOrientation in TickedVehicle.cs
  • Check for Rigidbody2D also - only one place - ApplySteeringForce in TickedVehicle.cs

Is this doable or do you not plan to support 2d projects at all?

I will try to test it during the week and send pull request with the changes.

Turning Radius

Hi,

I am not using unity steer or unity but I try to understand steering. I had some success so far but I struggle with the following problem and I hope that you as steering expert can help me.

I would like to apply steering to spaceships like fighters. When they move in one direction and I want them to make a 180 degree radius they slow down, turn and move to the other direction. This is totally fine for big battleships but fighters should keep their steep and make a nice turning. Is it possible to use this behavior with steering or would you solve it in the AI? Another option is to detect these cases and give them a nice path which also forces them to arrive at the arriving point with the right direction.

Sebastianw

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.