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 stingman · Apr 01, 2012 at 01:41 AM · rotationenemypathfindinglookatwaypoint

Enemy Not Facing target direction (waypoint) correctly when moving between waypoints

I'm working on a 2D sidescroller where my Z axis is always "0". I'm importing FBX Models from Cheetah 3d with animations attached. I have the animations set to loop when the enemy is moving back and forth between waypoints. It's a simple waypoint system where the enemy travels to one waypoint then turns to face the second waypoint and travels to it (constant loop). Just a ping pong waypoint system (simple patrol for an enemy). The problem is that the character never faces the right direction when moving from waypoint to waypoint. For instance... one enemy is about 45 degrees off of facing straight ahead... and when he hits his waypoint and turns around he's 45 degrees off of facing straight heading in the other direction. Another enemy is completely faced backwards. He literally moves backwards from waypoint to waypoint. I am not sure if it's my import settings that are screwing this up or if I should be doing something in a script that I'm not. Here is the latest script that I'm working with... wrote several different scripts, tried tons of tutorials, and other scripts and no luck still... same thing over and over... anyhow here's what I got... if anyone has any suggestions or solutions in JS or C# I'd appreciate it (p.s. it makes no difference if I reference global or local positions):

 var pathpoint : Transform[];                 var currentPathPoint : int;

var speed : float = 5; var loop : boolean = true; var player : Transform; var searchPlayer : boolean = false; var viewDist : float = 10; var maxPathDist : float = 40;

function Awake(){ pathpoint[0] = transform; } function Update(){ if(currentPathPoint < pathpoint.length){

var target : Vector3 = pathpoint[currentPathPoint].localPosition;

var moveDirection : Vector3 = target - transform.localPosition;

var velocity = rigidbody.velocity;

var playerDist : Vector3 = player.localPosition - transform.localPosition;

if(moveDirection.magnitude < 1){

currentPathPoint++;
}

else if(searchPlayer == true){

if(playerDist.magnitude < viewDist){

velocity = Vector3.zero;

target = player.localPosition;

velocity = (player.localPosition - transform.localPosition).normalized * speed;}

if((player.localPosition - pathpoint[currentPathPoint].localPosition).magnitude > maxPathDist){

target = pathpoint[currentPathPoint].localPosition;

velocity = moveDirection.normalized * speed;

} }

else{ velocity = moveDirection.normalized * speed; } }

else{ if(loop){ currentPathPoint = 0; } else{ velocity = Vector3.zero; } }

rigidbody.velocity = velocity; transform.LookAt(target);}`

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 SneezingCatP · Apr 01, 2012 at 02:21 AM

is the enemy facing on the blue line??

Comment
Add comment · Show 3 · 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 stingman · Apr 01, 2012 at 02:27 AM 0
Share

Ah I see what you are saying... the front of my enemy needs to face forward in the "Z" direction (blue line)... I looked at my enemies and sure enough this is the issue... do you know the way to fix this? And why would my characters not line up correct in the first place?

avatar image stingman · Apr 01, 2012 at 03:40 AM 0
Share

Got it working... if anyone has this issue there appears to be a few ways to fix it... but I went back into Cheetah 3d and repositioned my object so it lined up straight with the Z axis.

avatar image Owen-Reynolds · Apr 01, 2012 at 02:36 PM 0
Share

This is an extremely common question, has been answered over and over, but I don't think "facing backwards" or "facing wrong way" is a keyword, so difficult to search.

$$anonymous$$ost common answer given is to child the wrong-facing object, adjust the facing, and have the parent do the ai$$anonymous$$g. "Best" answer is to fix it in the modelling program (but some plp aren't able to do that.)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotating enemy object to face the player when moving 2 Answers

Enemy detection while pathfinding through the map 1 Answer

turn object to other object in 2D 1 Answer

Smooth Look causing Vector is Zero error... 2 Answers

How do I get GameObjects to look at me? 2 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