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 Zepeck · Mar 19, 2014 at 07:01 PM · movementaienemydirectiontorque

Unity2D, How do i check which way a sprite is facing?

In the game im creating, the enemies can only move forward and apply torque to turn(i know how to do this). What i need to do is find out which way the sprite is facing so i can add logic to decide whether the AI applies torque in the correct direction or moves forward.

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 trololo · Mar 19, 2014 at 07:21 PM 0
Share

We need more infos here (or an image to explain). You could use Quaternion.Angle() to compare the rotation angle between 2 sprites (but in don't think this is what you want) or trace a raycast with Physics.Raycast() to see if your sprite is rotated in front of a another one, etc.

avatar image Zepeck · Mar 19, 2014 at 07:31 PM 0
Share

$$anonymous$$$$anonymous$$akesGames has got the idea of what i want, ill uplaod a picture now though.

avatar image Zepeck · Mar 19, 2014 at 07:39 PM 0
Share

@trololo http://i.imgur.com/9jpQVfn.jpg

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TomMakesGames · Mar 19, 2014 at 07:28 PM

Do you actually want to apply torque? Do you need the physics. In many 2D games you may be better off making your objects kinematic and using angles etc.

Anyway, if you DO need the physics, then I think you want to look at using transform.forward. This will return a vector which gives the forward facing direction of your enemy. Compare that to whatever angle is relevant and then apply logic accordingly.

e.g. (pseudo-code)

if enemy's transform.forward is towards the player, keep moving forward. If enemy's transform.forward is not towards player, then turn clockwise to face them.

etc.

Does that help?

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 Zepeck · Mar 19, 2014 at 07:30 PM 0
Share

@$$anonymous$$$$anonymous$$akesGames Yeah that does help, how do i check if the forward facing direction is towards my hero though? And could you possibly explain the other method of kinematics?

avatar image TomMakesGames · Mar 20, 2014 at 05:15 PM 0
Share

Unfortunately I'm a beginner as well, and I wouldn't be able to come up with a solution off the top of my head and I don't have time at the moment to work on something for you. But it does look like you want the physics route, since you're effectively making asteroids. Stick with that (based on your pic).

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

22 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

Related Questions

Enemy AI Movement Decision Making 1 Answer

Enemy AI With changing Player 0 Answers

Unity AI/Enemy won't move towards target 0 Answers

Enemy controller.move script slows down and speeds up. How to get it consistent? 0 Answers

Enemy Spaceship Movement AI Curve Movement Need help Please 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