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 /
avatar image
0
Question by FuryFight3r · Dec 31, 2016 at 03:21 PM · movementvector3modelmovement script

Vector3 Head movement for model on TriggerEnter

Hi there guys, I've been trying to make a quick little script so that when i walk into the trigger, i have a girl sitting on a rocking chair, and when you go near her, she stops rocking (anims for chair and Jill are disabled, also the rocking chair sound effect) then when i leave the trigger she starts rocking again... all this works fine, but while standing in the trigger, i wanted the model to look at my character and follow with only head movements as i walk around her, i did have it at a stage where she would move her head, but not looking at me, and wouldn't move her head as i walked around inside the trigger, she would just snap her neck and look sharply to the right, without a slerp, i also wanted a function to reset her head position back to normal after exiting the trigger. this is the code i have,

EDIT: seeing as all my questions are stupidly put up for moderation as soon as i post them, here is what i have done in the 8+ hrs it took for this post to become publicly visualised. i changed the Vector from being called in the Collision and put it in an Update function, it now works to an except-able standard, but 2 things are still giving me issues, the model 'Jill' when entering the trigger and looks at me, she is not actually looking at me, if i am on the right side of her, and am reasonably close to her, she looks straight ahead, but as i move backward her head slowly starts to veer toward my direction until i leave the '7' distance, but however if i go to the left side of her she looks directly at me, which is what I'm trying to achieve, and if i move around her to the right hand side she just straightens up again and, again will only look to the right hand side if i move away from her, also the other issue I'm having is the Sphere Collider I'm using as the Trigger, seems to have somewhat of a Mesh Collider on it, and sometimes does not allow me to walk through it, or slows my char down before proceeding through the 'is Trigger' Collider and the same with Exiting the Collider. have also provided a video to give a visual reference as to the sphere collider YouTube Video Link

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class JillWatchTrigger : MonoBehaviour {
 
     public Animator jillsAnim;
     public Animator chairAnim;
     public Transform jillsHead;
     public AudioSource sounds;
     public Transform Player;
     bool isTriggered = false;
 
 
     private void Update()
     {
         if (isTriggered)
         {
             Vector3 direction = Player.position - this.transform.position;
             jillsHead.transform.rotation = Quaternion.Slerp(jillsHead.transform.rotation, Quaternion.LookRotation(direction), 1.5f);
         }
     }
 
     void Start () {
         jillsAnim.enabled = true;
         chairAnim.enabled = true;
         sounds.enabled = true;
     }
 
     private void OnTriggerEnter(Collider other)
     {
         jillsAnim.enabled = false;
         chairAnim.enabled = false;
         sounds.enabled = false;
         isTriggered = true;
     }
 
     private void OnTriggerExit(Collider other)
     {
         jillsAnim.enabled = true;
         chairAnim.enabled = true;
         sounds.enabled = true;
         isTriggered = false;
     }
 
 }

i am okay i guess with coding in general, but am just struggling with the Vector movement and rotations, if someone could explain to me more thoroughly on how they work that would be excellent.

i have no clue on where to even start on making her head position reset back to normal after exiting.

Thank you very much for any assistance!

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

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Vector Movement,Vectorel Movement with Buttons 2 Answers

Get a position relative to a gameobject 0 Answers

Convert WASD to local rotation 1 Answer

Can't move player with rigidbody.velocity 1 Answer

Problems with diagonal movement. 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