• 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 DroidifyDevs · Apr 17, 2016 at 03:32 PM · c#scripting problemcartransform.lookatbots

How to limit rotation speed when using Transform.LookAt?

Hi!

So I'm making bot cars for my game where they drive towards the player and chase him. Here's the script:

 using UnityEngine;
 using System.Collections;
 
 public class BOTAI : MonoBehaviour {
 
     private Rigidbody rb;
     public int AddForceAmount;
     public int bothealth;
     public Transform PlayerToLookAt1;
     public Transform PlayerToLookAt;
     // Use this for initialization
     void Start ()
     {
         AddForceAmount = 2000;
         PlayerPrefs.SetInt("AddForceAmount", AddForceAmount);
         rb = GetComponent<Rigidbody>();
         PlayerToLookAt = GameObject.FindWithTag("Player").transform;
         PlayerPrefs.SetInt("CarID", 2);
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (PlayerPrefs.GetInt ("BotLife") == 1) 
         {
             AddForceAmount = PlayerPrefs.GetInt ("AddForceAmount");
             rb.AddForce (transform.forward * AddForceAmount);
             transform.LookAt(PlayerToLookAt);
             transform.LookAt(new Vector3(PlayerToLookAt.transform.position.x, transform.position.y, PlayerToLookAt.transform.position.z));
             rb.AddForce (transform.forward * AddForceAmount);
             //Debug.Log("BOT looking at CarID3");
         }
     }
 }

Problem is, if the player gets rammed and ends up on top of one of the bots, the bots can spin instantly, looking very bad. Or if the player drives past a bot, the bot will instantly turn around. This looks very bad and cheap in the project. How can I limit the amount of degrees the bot can turn per second?

Or if there is a better way let me know, I'm open to all ideas.

Thanks :)

Comment
Add comment · Show 1
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 Shilola98 · Apr 17, 2016 at 06:09 PM 0
Share

Try this http://answers.unity3d.com/questions/48789/how-to-control-the-speed-of-look-at.html

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

145 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with Unity Vehicle Assets: Car isn't working at all 1 Answer

Trying to have bullets travel in the direction the player is facing 0 Answers

Can't Add Script "The script needs to derive from MonoBehaviour!" 1 Answer

Question about triggering an event (Extremely Novice to Programming) 1 Answer

Photon SetCustomProperties not working for previously connected players 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges