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
1
Question by Pixel2604 · Mar 11, 2016 at 01:13 PM · collisioncharacterlookat

Help for Realistic car Chase/Pursuit

Hey,
After long research on the net, i've not found a lot of answer to my question ... It's why i'm asking for your help !
I work on a small car game where a car (the player) must survive a amount of time avoiding ennemy cars, who are trying to hit him. More the time you survive, more ennemy are spawning ! Until now I don't have encounter any trouble (I've some knowledge in code)
But my Ennemy AI script is very basic and it's make the game to easy : It just lookAt the Target et move to him !
But i would like to make something more realistic and more fun :
https://www.youtube.com/watch?v=22FTp5T--XU
Something like this ! I've found this lesson : http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-pursuit-and-evade--gamedev-2946
I've undestood the theory but i need some Help for the Script !
Thanks you !
Sorry for my English !
Matthieu

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
1

Answer by Pixel2604 · Mar 11, 2016 at 05:18 PM

Edit :
I've done that :
using UnityEngine; using System.Collections;

 public class Steering2 : MonoBehaviour {
     public int Iteration = 30;
     public GameObject targetObject;
     public Transform target;
     public Controller TargetScript;
     public Vector3 targetSpeed;
     public float rotationSpeed;
     public float speed;
     // Use this for initialization
     void Start () {
         targetObject = GameObject.Find ("Car");
         target = targetObject.GetComponent<Transform> ();
     }
 
     // Update is called once per frame
     void Update () {
         TargetScript = target.GetComponent<Controller> ();
         targetSpeed = TargetScript.InstantVelocity;
         Vector3 FuturPosition = target.transform.position + (targetSpeed * Iteration);
         Vector3 Direction = FuturPosition - transform.position;
         Direction.y = 0;
         transform.LookAt (target);
         transform.rotation = Quaternion.Euler (270f, transform.rotation.eulerAngles.y, 0f);
         //transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Direction), rotationSpeed * Time.deltaTime);
         Vector3 moveVector = Direction.normalized * speed * Time.deltaTime;
         transform.position += moveVector;
 
     }
 }
 


But i've a problem when the target change turn direction, all the police car are going backward !

Comment
Add comment · 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

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

67 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiplayer Question 1 Answer

Colliders Don't Work no matter what 1 Answer

Adding collisions to a custom character controller? 1 Answer

LookAt() disables the collision of my 2d object 2 Answers

Player pushes object but gets pushed into the Wall/Boundary 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