- Home /
enemy character gameobject not working as intended
My enemy character which I imported from Mixamo is working weirdly. According to the script I wrote its Spine bone should look the way of the target(another gameobject) but it's not doing that.
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemycont : MonoBehaviour
{
public Transform targetTransform;
public Transform aimTransform;
public Transform bone;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 targetPosition = targetTransform.position;
AimTarget(bone, targetPosition);
}
void AimTarget(Transform bone, Vector3 targetPosition)
{
Vector3 aimDirection = aimTransform.forward;
Vector3 targetDirection = targetPosition - aimTransform.position;
Quaternion aimTowards = Quaternion.FromToRotation(aimDirection, targetDirection);
bone.rotation = aimTowards * bone.rotation;
}
}
I have checked the code several times and I am not able to find any problems. I added a debug line its code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Addline : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
OnDrawGizoms();
}
void OnDrawGizoms()
{
Debug.DrawLine(transform.position, transform.position + transform.forward *50);
}
}
and the line is following the target gameobject, but the spine of the character is not moving that way. image:
as you can see that the ray is facing towards the target but the character is looking somewhere else.
here are the properties of that character:
please refer to the hierarchy and the inspector.
The character is set to humanoid, animation on it is for humanoid objects. Everything is done normally I guess. What could be causing this problem and how do I fix it?
Also after adding the M4A1 gun object the spine started acting weird. image: https://imgur.com/a/ctnG54S
The thing to change the transform settings of the spine moved near the Gun instead of being on the spine after adding the gun.
So what's causing this problem and how can I fix this? Tell me if ya need more info. Cheers
Your answer
Follow this Question
Related Questions
How to separate bones from a 3dsMax skeleton? 0 Answers
Character Aiming 1 Answer
AddMixingTransform Help 0 Answers
Ignore Bones in Animation 1 Answer