- Home /
Player Launched Into Air Problem
I'm getting some weird behavior that I hope someone might be able to pinpoint. When I use the community "HeadLookController" found here:
http://wiki.unity3d.com/index.php?title=HeadLookController
I have modified it to include a few new lines:
public bool lockToPlayer = true;
public Transform currentTarget = null;
...
...
void Update() {
if (lockToPlayer == true && GameObject.FindGameObjectWithTag ("PlayerCamera") != null) {
currentTarget = GameObject.FindGameObjectWithTag ("PlayerCamera").transform;
}
if (currentTarget != null)
target = currentTarget.position;
}
void LateUpdate () {
if (currentTarget == null)
return;
...
...
...
I get the problem that when my npc looks at the player they're launched into the sky:
However, when I disable the "HeadLookController" I don't get this problem.
Here is what I have on my NPC:
Here is the root level that I have on my Player:
Both NPC and player have ragdoll applied but currently all the rigidbodies are marked as Kinematic in an effort to "disable" it until the player/npc has reached a death state.
Has anyone ever had this problem before?
Did you try to move the scripts into "FixedUpdate"? Are the colliders in a collision situation?
@Alan$$anonymous$$attano I actually haven't tried that. I will try that and see how it goes, thanks for the suggestion. As far as colliders go it's possible... I have tried to disable the multiple colliders on the same level but maybe the ragdoll colliders are causing issues.
@Alan$$anonymous$$attano Thanks so much for the suggestions. I moved that piece of code to the "FixedUpdate" while that didn't fix my launching problem I think you're right to tell me to move that their anyway. It will be more efficient anyway. As I was testing the colliders I noticed that the collider for his head was massive. This was the problem. A collider within a collider situation un-knowingly. So I changed it to a normal size and I don't randomly launch into the air anymore. However, I do get a slight jump when I get too close and the NPC plays the crouch animation. It's probably because his head enters the player collider causing him to jump.
Is there a way to prevent the player from getting too close to the NPC that you might be able to suggest?
Btw you should change your comment into an answer so I can accept your suggestion and close this question. Thanks for you help! :D
Answer by AlanMattano · Aug 13, 2017 at 12:29 AM
Like @wesleywh said, when you spawn a physics game object with RigidBody attach to it and is reacting in a strange behaviour, try to look if the colliders are touching some other collider. If it does, this can trigger big forces on the less heavy physic object. Especially if the mass difference is too big. Also, remember to use FixedUpdate when you deal with physics.
Your answer
Follow this Question
Related Questions
Multiple Controller Issue (They only work if both controllers are inputting something) 1 Answer
First Person controller turned into a rocket ship 2 Answers
Why does the .controller file get modified when opening Unity? 3 Answers
Permanent unintentional Input on Axis 1 Answer
Child object consistency issue 1 Answer