Physic gets slow down

Hi all!

First I want to thank you for all the good work with Unity3D engine and with this forum, because until now I have solved all my questions!

We are making a game that uses a little bit of physics for ball collision and reaction. We are also using forces to move the ball. The main problem comes when we use the events “OnCollisionEnter” and “OnCollisionStay”, after this events are executed when we call again AddForce over the ball, the force added is not as big as before.

For example:
First time I shot the ball I use AddForce with (245.2, 0.0, 5995.0)
and the speed of the ball is 117.6255

but after game executes OnCollisionStay (the object is 3 sec colliding)

I call AddForce with (474.5, 0.0, 5981.2)
and the result speed is 60.01628

I find nothing in the documentation about this behaviour.

Any help is welcomed :slight_smile:

Which ForceMode do you use? Maybe try ForceMode.Impulse

I have tested and same result

some sample code would be nice to test the behaviour.

Does the material change?

Hi again!

Well, there is no material change and I have experienced this weird behaviour with any script.

This is the code I’m using now:

using UnityEngine;
using System.Collections;

public class ResetBallWhenOutOfFloor : MonoBehaviour
{
	public float TimeForReset = 3.0f;
	
	/// Logic ball
	GameObject mMainBall;
	
	/// Physic ball
	GameObject mBall;
	
	/// Time until reset
	float mTimeColliding;

	// Use this for initialization
	void Start ()
	{
		if (!collider)
		{
			Debug.LogError("Object " + name + " has Terrain script added and has not collider");
			enabled = false;
			return;
		}
		
		mMainBall = GameObject.FindWithTag("Main Ball");
		if (!mMainBall)
		{
			Debug.LogError("Main Ball has not been found");
			enabled = false;
			return;
		}
		
		mBall = GameObject.FindWithTag("BolaGolf");
		if (!mBall)
		{
			Debug.LogError("BolaGolf has not been found");
			enabled = false;
			return;
		}
	}

	void OnCollisionEnter(Collision colInfo)
	{
		Debug.Log("Colliding with Terreno");
		if (colInfo.collider != mBall.collider)
		{
			return;
		}
		
		mTimeColliding = 0;
	}

	void OnCollisionStay(Collision colInfo)
	{
		if (colInfo.collider != mBall.collider)
		{
			return;
		}

		mTimeColliding += Time.deltaTime;
		if (mTimeColliding >= TimeForReset)
		{
			GolfBall gb = (GolfBall) mMainBall.GetComponent(typeof(GolfBall));
			gb.OnFallingOutsideCircuit();
		}
	}
}

After the ball resets, when I use the same force that before, the ball gets half of the speed…

Anyway, I will use a trigger if I can’t fix this problem :slight_smile:

No one has experienced this?

Hi all!

Finally I fixed the problem using raycasting to see if I was over the collision instead of using the “OnEnterCollision, OnStayCollision and OnExitCollision” events.