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
1
Question by maspi · Nov 26, 2011 at 12:57 AM · first-person-controllerinteraction

Independent animal character interacts with 1st Person Controller

In a 1st Person Game I want to let interact an independent animal with the 1st Person controller.

If the animal is in the Back of the 1st Person, it will run to the 1st P. and steal points. If the 1st P. turns and faces the animal it will run away.

I am grateful for solution strategies.

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
Best Answer

Answer by aldonaletto · Nov 26, 2011 at 01:26 AM

That's the basic idea: get a vector from the animal to the fpc (toFpcDir) and check the angle between -toFpcDir (a vector from the fpc to the animal) and the fpc forward direction; if it's less than some narrow angle (15, in the pseudo code below) the fpc is looking in the animal direction, thus make it beat the road; if greater than this angle, continue moving in the fpc direction until a minimum distance is reached, when you could do the attack and apply damage - something like this (animal script):

var fpc: Transform; // drag the First Person Character here

function Update(){ var toFpcDir = fpc.position - transform.position; // animal->fpc direction var angle = Vector3.Angle(-toFpcDir, fpc.forward); // check the angle if (angle < 15){ // FPC is facing the animal: // run away or go back } else { // FPC is looking to other direction: // continue and attack } } The actual movement of the animal will depend on which kind of object it is. Usually live creatures are based on a CharacterController, thus you should move it with Move or SimpleMove, taking advantage of the calculated toFpcDir vector. You must also decide what exactly the animal will do when the fpc look at it: go back slowly, or turn 180 degrees and run, or a mix of the two things etc.

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 maspi · Nov 26, 2011 at 08:02 PM 0
Share

That's exactly what I was looking for!

Thank you very much for the clear explanation an the simple and useful code snippet.

avatar image aldonaletto · Nov 27, 2011 at 03:59 PM 0
Share

@maspi, if this answer solved your problem, please click its accept button (the "check mark" button below the voting thumbs) - this may help others to find the solution for similar problems.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

first person controller with interaction 2 Answers

Hide cursor and stop interaction 1 Answer

VR UI interaction with ingame hands 1 Answer

Navigate Without Focus? 0 Answers

XR Interaction Toolkit: most correct way of dealing with multiple interactors 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