Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 RealSoftGames · Jul 12, 2015 at 12:30 PM · rotationlookatlookattarget

Alternatives to LookAt()

Hi im creating an AI Script and i am starting to look away from the dodgy things i started out with such as the LookAt() for Ai.

reason being is i cant use velocity to track its rotation to play the appropriate animations and i want to learn something new.

what i have tested is

Cross Product Dot Product and also manually altering the rotations of the enemy, i have successfully done so using a rigidbody with Getcomponent().angularVelocity , this also plays the correct animation when done so, but the issue im having is getting the enemy to stop rotating when he is facing the player, i know i can hack this in with a simple raycast, if hit player move forward and stop rotating, but the issue with that approach would be when its not hitting the player how does it know how to turn CW or CCW ??

so i have been digging for a different approach and thought i would turn to the community for some help with this.

essentially i have a few waypoints on the map to test with atm but i cant seem to get the AI to face the object, and i do not want to resort in using Transform.LookAt() as it defeats the purpose. and can not play animations such as rotating as it locks to the object and does not Slerp to it. i do see this question posted a fair bit, but their never seems to be an answer to the question that works.

Thanks in advanced for taking the time to pitch in to this topic.

Comment
Add comment · Show 2
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 timohausmann · Jul 12, 2015 at 01:22 PM 0
Share

what exactly do you want to do? Slerp an objects rotation to face another object?

avatar image RealSoftGames · Jul 12, 2015 at 04:03 PM 0
Share

I'm creating a soldier AI, I had made a small prototype, although it worked with the legacy animation and the navmeshagent AI unity supplies. I want to create it from complete scrap. That goes for movement and sight of the AI. So starting small. Like we do 1 step at a time, since this sort of rotation is something I strugle most with I thought I would ask for some help with it.

The rotation I'm after is very similar to the look at. But I need to know when I'm actually looking towards the target so I can apply tthe correct movement. $$anonymous$$g not facing target and running sideways. I plan on adding 8directional movement for AI. Basic forward back, left right. And strafing. All while looking towards the target the AI can still move freelyaround the map while firing at the player without snap locking. Which transform.LookAT does.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by globalenemy · Jan 28, 2016 at 01:23 PM

Your, idea to approach the problem via raycast isn't too bad. well maybe it's a bit loaded. You can simply calculate an angle from the Enemy to the Player and check this back with the current rotation of the Enemy.

Since you're not using RotateTowards or LookAt, you might get into the problem, that the Enemy will never actually reach the desired rotation. Causing it either to continue rotating or switching between rotating back and forth very close to the target angle, depending on your code.

I might be talking bullshit here, but your problem sounds very similiar to one I had some time ago: http://answers.unity3d.com/questions/1088611/how-to-do-quaternionrotatetowards-on-single-local.html#comment-1089733 (the linked comment shows the solution to the back and forth problem.

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

23 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 avatar image

Related Questions

Simulating Mouse Input for AI 0 Answers

How to make AI look at player 0 Answers

!Urgent! How to get a sprite to look at another object? 1 Answer

LookAt Camera over 90 degree 1 Answer

Is it possible to rotate a child object regardless of the parent rotation ? 1 Answer


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