Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by andyblem · Dec 16, 2014 at 04:26 PM · c#steering

How to add to implement the Arrive steering behavior

I am trying to implement the arrive steering behavior. The thinking behind is my game entity should move towards a target at a certain speed. when the entity is within a certain distance away from the target it should decelerate until it stops at its target. I tried to implement this but something crazy happens. If i use a radius like of magnitude 5 my game object just moves past its target and continues to do so. If I select a larger radius like 50 or hundred my object decelerates and come to a stop but it will be before it reaches its target. Here is my code of what I am trying to do

 /**
      * This behavior is similar to seek but it attempts to arrive at the
      *  target with a zero velocity
      */
      public Vector3 Arrive(){
          //find the required velocity to reach the target
         direction = target - m_pPlayerPos;
         direction.y = 0;
         //find the distance between object and target
         float distance  = direction.magnitude;
         //value to hold the deceleration value
         float deceleration;
         //value to hold the required steering force
         Vector3 steeringForce;
         
         //check to see whether the character 
         //is inside the slowing area
         if(distance < slowingRadius)
         {
             //inside the slowing area(use newton's equation v^2 = u^2 + 2as)
             deceleration = (0 - (moveSpeed * moveSpeed))/ (2 * slowingRadius);
             moveSpeed += deceleration;
             
             steeringForce = direction.normalized * Time.deltaTime * moveSpeed;
         }else{
             
             //outside the slowing area
             steeringForce = direction.normalized * Time.deltaTime * moveSpeed;
         }
         
          
         
         return steeringForce;
      
      }

Here is where the Arrive is called by the game object

 //instance of the steering behaviours
     public SteeringBehaviours m_pSteering;
     //variable to store the ball
     protected GameObject m_pBall;
     // Use this for initialization
     public void Start(){
         
         m_pSteering = new SteeringBehaviours(new Vector3(transform.position.x,transform.position.y,transform.position.z));
         m_pBall = GameObject.FindGameObjectWithTag("soccerBall");
     }
     // Update is called once per frame
     void Update () {
         m_pSteering.SetTarget(m_pBall.transform.position);
         //FaceBall();
         transform.position += m_pSteering.Arrive();
         
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Dave-Carlile · Dec 16, 2014 at 04:31 PM

I think the idea is to clamp your velocity by the remaining distance so it's reduced from the max down to zero as you approach...

 if (distance < ArrivalDistance)
 {
     desiredVelocity = Vector2.ClampMagnitude(desiredVelocity * distance, MaxSpeed);
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andyblem · Dec 17, 2014 at 07:27 AM 0
Share

I have not yet tried your solution but here is what I tried again. The problem is my gameobject does not stop at its target. It stops a certain distance away from the target. Here is my code public Vector3 Arrive(){ //find the required velocity to reach the target direction = target - m_pPlayerPos; direction.y = 0; //find the distance between object and target float distance = direction.magnitude; //value to hold the deceleration value float deceleration; //value to hold the required steering force Vector3 steeringForce = new Vector3();

         //check to see whether the character 
             //inside the slowing area(use newton's equation v^2 = u^2 + 2as)
             deceleration = (0 - (moveSpeed * moveSpeed))/ (2 * distance);
 
             moveSpeed += (deceleration/distance);
             
           return  steeringForce = direction.normalized * Time.deltaTime * moveSpeed;
     
      
      }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

How to manupulate objects in 3d(Steering Behaviours) 0 Answers

A* Pathfinding and Driving Cars. How do I calculate the torque when the waypoint is perpendicular to the car 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges