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 Dec 19, 2016 at 09:46 PM by TBruce for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Wtfn · Dec 19, 2016 at 08:52 PM · 2d2d gameenemypathfinding

Gameobject not moving unless starting at 0 transform

I'm making a 2d game where the enemy is assigned a array of vector3's in the editor. That way I can set it's path along a grid of units that it moves to in a blocky way. It was working well but, after I changed the orgin point of the enemy gameobject off of 1,0,0 it doesn't work. I couldn't find any noticeable changes in any values while looking in the debug menu and I attempted to use some debug logs but they also didn't reveal anything. Note: I am using unity 4 as that's all my laptop supports.

Code:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyMovementController : MonoBehaviour {
 
     //Set in editor by level basis, holds pathfinding data for enemy.
     public Vector3[] EnemyPathArray;
     //Path segment in the Enemy Path Array.
     int PathSegmentArray;
     //Speed for movement;
     public float EnemyMovementSpeed;
     //Timer on when the enemy moves.
     float Speed;
     float EnemyMoveTimer;
     //Temp float for testing the time between moves for ideal timeing.
     public float EnemyMoveTimerCapTemp;
     //Bool for moving enemy
     bool EnemyMoving;
     //Movement Array for enemy position.
     public GameObject Enemy;
 
     void Start(){
         EnemyMoveTimer = EnemyMoveTimerCapTemp;
         PathSegmentArray = 0;
 
     }
     void Update(){
         if (!EnemyMoving) {
             EnemyMoveTimer -= Time.deltaTime;
             if (EnemyMoveTimer <= 0) {
                 EnemyMoving = true;
             }
         }
         if (EnemyMoving) {
             Speed = EnemyMovementSpeed * Time.deltaTime;
             MoveEnemy();
         }
     }
     void MoveEnemy(){
         //Debug.Log ("Moving Enemy");
         Debug.Log (PathSegmentArray);
         Enemy.transform.position = Vector3.MoveTowards (Enemy.transform.position, EnemyPathArray [PathSegmentArray], Speed);
         //Debug.Log (test + "this.transform");
         //Debug.Log (EnemyPathArray [PathSegmentArray].y + "Target transform");
         if (Enemy.transform.position == EnemyPathArray [PathSegmentArray]) {
             PathSegmentArray += 1;
             if(PathSegmentArray > EnemyPathArray.Length - 1){
                 PathSegmentArray = 0;
                 //Debug.Log("Setting path segment to 0");
             }
             EnemyMoveTimer = EnemyMoveTimerCapTemp;
             EnemyMoving = false;
 
         }
     }
 }


Comment
Add comment · Show 3
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 Wtfn · Dec 19, 2016 at 07:39 AM 0
Share

note: I debug logged the position vector of the enemy right after the movetowards func should be getting called. It says that stuck at -.9 on the x. I'm trying to go from -1x to 0 x and it's getting stuck at -.9.

avatar image Wtfn · Dec 19, 2016 at 08:09 AM 0
Share

O$$anonymous$$! It's the animator that's causing it. Idk what is wrong with it but I'm gonna fix it.

avatar image Wtfn · Dec 19, 2016 at 08:11 AM 0
Share

Yep my Enemy's idle animation was screwing it up. It didn't actually have anything in it and i think it was causing problems one way or another.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enemy's initial attack doesn't deal damage to player 1 Answer

AI & pathfinding for 2D platformer - how to approach? 0 Answers

Why is my gameObject falling so slow? 1 Answer

How do I go about making a 2d platform enemy ai 1 Answer

2D Pathfinding Top Down 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