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 Exce · Jul 01, 2012 at 06:22 AM · forwardsimplemove

controller.simplemove having issues with vector3.forward

EDIT: See my comment response below this post

I am trying to simply move my enemy forward (using the character controller) by calling SimpleMove.

First off, I got this to work no problem with my player class. I copied the bits and adjusted them and applied them to my enemy class and its not working. The enemy sort of jerks in the forward direction for a few frames, then immediately goes the wrong direction for about 1.5 seconds, then jerks into the forward direction, etc...etc...alt text

I've included this wonderful illustration to show what I mean. He move forward, then slides the wrong way for a bit, then forward. I have the character controller and character motor set up identical to my player class and its just not working. Any ideas?

using UnityEngine; using System.Collections;

 public class EnemyController : MonoBehaviour {
 public int health;
 public AudioClip hit;
 public AudioClip die;
 float distanceCheck;
 Vector3 desiredDirection;
 public Transform PlayerPosition;
 public float runSpeed;
 public float rotationSpeed;
 CharacterController controller;
 // Use this for initialization
 void Start () {

 animation["gethit"].layer = 2;
 animation["gethit"].speed = 1f;
 animation["waitingforbattle"].layer = 1;
 animation["die"].wrapMode = WrapMode.ClampForever;
 animation["die"].weight = 1;
 animation["die"].layer = 3;
 }
 
 // Update is called once per frame
 void Update () {
     controller = GetComponent<CharacterController>();
     distanceCheck = Vector3.Distance(PlayerPosition.position, transform.position);
     desiredDirection = (PlayerPosition.position - transform.position);        

     controller.SimpleMove(transform.forward * runSpeed);

     if (health <=0)
     {
         animation.Play("die");
         animation.wrapMode = WrapMode.ClampForever;
     }
     else        
         animation.CrossFade("waitingforbattle");
 
 }
 
 public void getHit(int damage)
 {
     health -= damage;
     
     if (health > 0)
     audio.PlayOneShot(hit);
     else
     audio.PlayOneShot(die);
     
     animation.Play("gethit");
 }

}

Example.png (19.6 kB)
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 Exce · Jul 01, 2012 at 05:44 AM 0
Share

Alright...so I found out that for whatever crazy reason the following line of code causes this to happen.

 else     
    animation.CrossFade("waitingforbattle");

Why does playing an animation cause my player to run erratically? If I comment this out, he move properly.

2 Replies

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

Answer by aldonaletto · Jul 01, 2012 at 06:50 AM

I suspect you may have some object with a collider childed to your character - the character controller behaves weirdly when some child collider touches its capsule: it "thinks" to be colliding with its own child and moves to weird directions. If you have such object, set its collider Is Trigger field, and the character will ignore it.

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 Exce · Jul 01, 2012 at 03:28 PM 0
Share

You were right. I have a capsule collider on the enemy's weapon. I use it to detect if he hits the player. Setting it to trigger should allow me to still detect hits. Thanks for the solution.

avatar image
0

Answer by ternitet · Feb 06, 2015 at 10:04 AM

Bit late, but if others come this way with the same question, I'd like to provide my insights on this very problem:

Applying a SimpleMove() to a GameObject with a CharacterController may fail if that GameObject has a NavMeshAgent component attached.

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

7 People are following this question.

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

Related Questions

how to ignore transform.position.y 3 Answers

transform shooting forward 2 Answers

Difference between transform.forward and transform.position.z? 1 Answer

How do I add a forward and backward move by a swipe to my iOS script? 1 Answer

movement doesnt stop when jump pad is tapped at the same time 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