Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by andyblem · Jan 05, 2016 at 04:49 AM · c#aisteering

How to create steering behaviours for a goal keeper

I am trying to set up a soccer game. I have managed to set up an A.I that plays by itself observing different rules of the game. My steering behaviors have worked well for my field players but not as I would have wanted for my goal keeper and other motions like back paddling or side movements. At the beginning I have designed my behaviors in a way such that a player simply rotates to face his direction and move in that way. Now I want to implement more complex movements like back paddling side movements etc. So I redesigned my behaviors in a way such that a player now has a steering target("where he moves to") and a track target("where he always looks at ") e.g a player might decide to move to a certain home region behind him whilst looking at the opponents's goal or ball. So I tried to implement this design but it does not work, removing the code that rotates the player results in my player only moving forward along the Z-axis. And if I add the code for the player to rotate and look at its target that code is being overridden somehow and the player only faces its steering target and not the track target. Here is my seek behavior before adding the track target code

 direction = steeringTarget - m_pPlayer.transform.position;
         direction.y = 0;
         direction = direction.normalized;
         
     
         
         if (directionToTrackTarget != Vector3.zero) {
             m_pPlayer.transform.rotation = Quaternion.Slerp (m_pPlayer.transform.rotation, Quaternion.LookRotation (direction), Parameters.MaxRotationSpeed * Time.deltaTime);
             m_pPlayer.transform.eulerAngles = new Vector3 (0, m_pPlayer.transform.eulerAngles.y, 0);
         }
         
         Vector3 forward = m_pPlayer.transform.TransformDirection(Vector3.forward);
         float speedModifier = Vector3.Dot(forward, directionToTarget.normalized);
         speedModifier = Mathf.Clamp01(speedModifier);
         
         direction = forward * Parameters.MaxSpeed * speedModifier;
         
         m_pPlayer.GetComponent<CharacterController>().SimpleMove(direction);

Here is my updated steering behaviour

             //calculate the direction vector to steering tagert
             directionToTarget = steeringTarget - m_pPlayer.transform.position;
         directionToTarget.y = 0;
         directionToTarget = directionToTarget.normalized;

             //calculate the direction vector to look position and rotate the player
         directionToTrackTarget = trackPos - m_pPlayer.transform.position;
         directionToTrackTarget.y = 0;
         directionToTrackTarget = directionToTarget.normalized;

             //rotate the player
         if (directionToTrackTarget != Vector3.zero) {
             m_pPlayer.transform.rotation = Quaternion.Slerp (m_pPlayer.transform.rotation, Quaternion.LookRotation (directionToTrackTarget), Parameters.MaxRotationSpeed * Time.deltaTime);
             m_pPlayer.transform.eulerAngles = new Vector3 (0, m_pPlayer.transform.eulerAngles.y, 0);
         }
         
         Vector3 forward = m_pPlayer.transform.TransformDirection(Vector3.forward);
         float speedModifier = Vector3.Dot(forward, directionToTarget.normalized);
         speedModifier = Mathf.Clamp01(speedModifier);
         
         directionToTarget = forward * Parameters.MaxSpeed * speedModifier;
         
         m_pPlayer.GetComponent<CharacterController>().SimpleMove(directionToTarget);


I am using state machines and this is the experimental keeper state. In this state the keeper check if he is at his target. If he is at his target he tracks the ball("which works fine") else he has to move back to his position which is not workin.

     // Update is called once per frame
     override
     public void Execute (Keeper keeper)
     {
         //if the player is not at target make sure he moves towards his spawn point
         if (!keeper.AtTarget())
         {
             keeper.Steering().SetTrackTarget(keeper.Ball().transform.position);
             keeper.Steering().Arrive();
         }
         else
         {
             keeper.TrackTarget(keeper.Ball().transform.position);
             
         }
     
         //if the ball comes in hot region switch to tend goal
         if(keeper.SqrDistance(keeper.Ball().transform.position) <= 20 * 20)
            //&& !keeper.Pitch().IsGoalKick())
         {
             //keeper.GetFSM().ChangeState(ExTendGoal.Instance());
         }
     }



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

0 Replies

· Add your reply
  • Sort: 

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

Enemy watches player and shoots but bullets will not project.. 0 Answers

How do I make an AI(cube) that follows and rams the player? 0 Answers

A little doubt about creating a Talking BOT that simulates AI, for iOS system using Unity. 0 Answers

How to get a for loop to run once per coroutine? 1 Answer

A* Pathfinding for Top Down project, how do I make enemyAI to rotate towards waypoints? 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