3
\$\begingroup\$

I have a Player with a capsule collider on him and i have various objects in the scene. Most of the objects have either mesh collider or box collider enabled. When i move my player and the player collides with any object, my player just starts flying into space, literally. Any way to fix this?

Thanks in Advance.

The code i have on my player is this:

using UnityEngine; using System.Collections; public class Controller : MonoBehaviour { Animator anim; Rigidbody rbody; float inputH; float inputV; int Life=20; bool Dead=false; public float sensitivity=10f; void Start () { anim = GetComponent<Animator> (); rbody = GetComponent<Rigidbody> (); } void Update () { if (Dead == false) { inputH = Input.GetAxis ("Horizontal") * 50f; inputV = Input.GetAxis ("Vertical") * 20f; anim.SetFloat ("inputH", inputH); anim.SetFloat ("inputV", inputV); float moveX = inputV * Time.deltaTime; float moveZ = inputH * 0.5f * Time.deltaTime; this.transform.position += this.transform.forward * moveX; this.transform.position += this.transform.right * moveZ; transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivity, 0); } if (Input.GetKey (KeyCode.Z)) Life--; if (Life == 0) Dead = true; anim.SetBool("Dead",Dead); } } 
\$\endgroup\$
8
  • \$\begingroup\$ Check the rigidbody attached to your player. You might want to increase the player's mass, drag, and angular drag. See if that has any effect. \$\endgroup\$ Commented Sep 27, 2015 at 10:09
  • \$\begingroup\$ @Daniel I've tried that. It seems to have no effect at all. My player just keeps flying. I think maybe the collision adds a force on the player which makes him fly. And i don't know how to prevent that. \$\endgroup\$ Commented Sep 27, 2015 at 10:17
  • \$\begingroup\$ I've only ever seen that behavior when there are multiple objects with rigid bodies stacked on top of each other. If you have multiple child objects in one parent, make sure that there is only one rigid body in that entire object. Otherwise idk. \$\endgroup\$ Commented Sep 27, 2015 at 10:38
  • \$\begingroup\$ Only my player has a rigidbody and he has a single rigidbody for the whole of his structure including his body arms legs head etc. The other objects has only colliders and no rigidbody \$\endgroup\$ Commented Sep 27, 2015 at 10:41
  • 1
    \$\begingroup\$ Go to -> Edit -> Project Settings -> Physics. There's some more physics options there including bounciness. See what you can do with that. \$\endgroup\$ Commented Sep 27, 2015 at 10:46

3 Answers 3

1
\$\begingroup\$

I kinda solved it. I'm not sure whether it is a perfect solution. I just set the values of 'Drag' and 'Angular Drag' to "Infinity". I posted the answer here so that it might be useful to someone else. Thanks for your comments guys.

\$\endgroup\$
0
\$\begingroup\$

The solution I've observed with this issue is to simply remove the Rigid Body from one of the collided objects.

In my case a bullet was moving to hit the plane, and the plane was floating into space.(Similar to your issue)

I removed the rigid body of the plane, and this solved my problem. Now OnCollisionEnter is called.

\$\endgroup\$
0
\$\begingroup\$

I have found a great answer to this problem - in 1 specific occurrence at least.

My Ex:

I had some cubes that ran back and forth - and when the player (cube) collided with them - they would stop and slowly push on the player though.. - Anyway.. this worked fine until one day it started BOUNCING my player up into the sky out of NOWHERE!!! D : I tried several fixes - only to realize - that my Plane (floor) underneath the cubes had accidentally gotten moved up a few world units (in the z axis) - SOOOO... - now my plane was intersecting with my running cube objects - .. I moved the plane back down - and low and behold .. the problem went away. - so watch out for GROUND and surrounding object's intersecting with your objects that have rigidbodys at start because this can cause a LOT of bad problems. Hope this helps some ppl! : ) Happy GameMaking!'

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.