- Home /
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!
Your answer
Follow this Question
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