I’m trying to make character walking by arrows and aiming at target “enemy” but the problem here that my character pointing not at enemy !!. No matter how close or far from enemy. I don’t know what is the problem ? It’s from animation or something i’m missing with IK function ? I upload the whole scene “7mb” and I really hope some one here will solve this issue.
Don’t say that please. this something really simple. I’m not talking about climbing or acrobat moves. when they develop Mecanim IK they think on this thing of course.
Also, using “target.transform.position” didn’t change thing !! What else you advice me to do ?
Thank you for your reply.
OK, I did this before but nothing change. I don’t know where is me problem ? Could you please check scene file ?
Try debugging your code. Does line 50 ever gets called?
Does “attack” variable actually set in somewhere? It might be serialized as false in the inspector.
Looks like the character is aiming at the feet of the other character. That makes sense if your other character’s center is at it’s feet, which is pretty common.
To check it, put a sphere as a child of your other character, and position it at 0, 0, 0. That’s where it’s center is.
When you want IK to target something, you usually want the thing you target to have a concept of where it is that’s seperate from the model. I usually place an invisible marker child object where I want the thing to aim, and have my targeting scripts target that.
If you want a quick and dirty solution, you could instead get the skinned mesh renderer’s bounds, and use that for aiming - something like the center on x and z and the average of the center and the max for y will give you a target point at approximately center of mass.
Yes. It’s working.
I can’t believe that no one think on something like this before !!
What will happen if i want my enemy character shooting player above a tree ?
You right. the center or the character.
I added a sphere as a child and move it to the hip position. What i got is… aiming far from sphere, in close or far standing position !!!
The more strange is when i tried to get close at the point character targeting “which is the sphere” I found this !!
My character pointing at something I don’t know what is it on the ground !!!?
It’s a bug ? Please some one tell me what the crazy thing is this ?
You mean that mecanim IK will not aiming at target till i add new script to fix aiming issue ? OK. how to do that ? Could you upload a scene for me ? Because i tried many methods but i failed at the end.
SkinnedMeshRenderer is more heavy on CPU. If it will solve this problem…never mind. I added SMR to enemy idle object and shpere as a mash… every thing placed on the center of my enemy character and what i get…another fail !!
Sill I don’t know what is my mistake. Why my character doesn’t aim at target !?
So on this picture, you can clearly see that the look at for the head did work as the blue arrow( forward vector or Z vector) for the head is looking at you’re NPC. I did modify you’re script to show you this like this
Character_animator.SetLookAtWeight(1,0,1,0,0);
with SetLookAtWeight you can control 3 transform: chest,head and eyes
So that been said, this is not exactly what you want, yes you want your character to look at the target when you aim but you want your gun to aim at the target, so you want to align the forward vector of the gun on the target.
There is no builtin solution out of the box for this in Unity, it can be done with IK but you will need to build something to make it work or you can use an asset store package like FinalIK