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 /
This question was closed Apr 28, 2016 at 05:52 PM by MrProtato123 for the following reason:

Used another aproach

avatar image
0
Question by MrProtato123 · Apr 25, 2016 at 04:32 AM · c#aicrashing

Ai script(rotation) causes game to crash

Hey,

for my first attemps lerning unity and building my first game, Im using the script bellow. For some reason the game crashes once the ai gets closer to my player. I found out removing the "transform.Rotate" line(19) prevents the game from crashing. But of course the script isnt doing its job anymore once i removed this(ai keeps cricling, looks funny but its not what I want). Ive already spent about an hour trying to solve the problem but I cant find it... Maybe somone of you nice guys can help me with this

     using UnityEngine;
     using System.Collections;
 
     public class EnemyController : MonoBehaviour {
 
         public Transform target;//set target from inspector instead of looking in Update
         public float speed = 3f;
 
 
         void Start () {
 
         }
 
         void Update(){
 
             //rotate to look at the player
             transform.LookAt(target.position);
             transform.Rotate(new Vector3(0,-90,0),Space.Self);//correcting the original rotation
 
 
             //move towards the player
             if (Vector3.Distance(transform.position,target.position)>1f){//move if distance from target is greater than 1
                 transform.Translate(new Vector3(speed* Time.deltaTime,0,0) );
             }
 
         }
 
     }
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

  • Sort: 
avatar image
1
Best Answer

Answer by M-Hanssen · Apr 25, 2016 at 08:38 AM

There is nothing wrong with your script. Works fine on my end.

A few questions:

  • What version of Unity do you use?

  • Is it your intention to move the object sideways?

Comment
Add comment · Show 2 · 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 MrProtato123 · Apr 25, 2016 at 08:50 AM 0
Share

Hey,

can't tell you from here the exact version(im not at home), but it should be the latest stable one(downloaded like 3 days ago). $$anonymous$$y intention is to move the enemy object straight to the (moving) player object.

avatar image MrProtato123 · Apr 25, 2016 at 02:10 PM 0
Share

Its version 5.3.4f1 Personal

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Enemy pick and throw an object 1 Answer

AI scripting Question. 2 Answers

Can't properly duplicate an enemy AI 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