I am using a rigidbody sphere for my player in this project. Whenever I am making contact with a wall, my sphere doesn’t jump as high as it does out in the open. My initial thought was that this would be related to friction, but no matter what value I assign for friction, I see the same height on the jump when the player is up against the wall.
My initial thought was to try and use a cast of some kind that would prevent me from ever fully touching wall, but at some point I want to implement the ability to roll up walls and/or wall jump and that seems counterproductive.
Here is my movement code:
//Controls movement direction and speed, also sets our version of drag if the Player isGrounded.
void Movement(float x, float y, float z)
{
movement = ((x * forward) + (z * right));
rigidbody.AddForce(movement * ballSpeed * Time.deltaTime);
if(Mathf.Approximately(x, 0) && Mathf.Approximately(z, 0) && rigidbody.velocity.y < .1f)//isGrounded == true)
{
StartCoroutine(Delay (1));
rigidbody.velocity -= rigidbody.velocity * Time.deltaTime;
}
}
Well, it appears that using AddForce instead of incrementally increasing velocity along the Y axis may have been the problem. Using velocity instead of AddForce doesn’t give me a perfect result, but it’s much better than before. I’m waiting for some people to test my result before I call this “solved.”
For those interested, I changed the Jumping code to
Thanks to Xelareip, I have adjustd the jumpHeight value to a more appropriate level and removed Time.deltaTime from the velocity assignment. According to my team members, this satisfactorily solved the problem we were experiencing. During my own testing, I noted that using Xelareip's advice of lowering friction on the player collider and adjusting the friction combine to minimum would also provide a satisfactory solution.
Not sure of why you had the problem in first place but I think the inconsistent results of your second version comes from the Time.deltaTime.
When you jump you apply your velocity change only once and thus you don’t have to take in account the deltaTime.
Imagine you run the code at 100 fps, the initial velocity (the impulse when you jump) will be jumpheight / 100
Now, same code but at 20 fps, the initial velocity is jumpheight / 20
That means you will jump 5 times higher if your game runs 5 times slower.
Taking deltaTime in account makes sense for a continuous effect (like a drag) but not for a punctual one (like a jumping impulse)
Also I don’t see why setting the velocity instead of adding a force would change anything in your problem since what makes your ball fall back is continuous application of physic effects and has nothing to do with the initial impulse.
Have you checked both physic materials of your colliders? if one has friction and the friction combination mode is different than “minimum” you will still have some friction effect.
Thanks for your help with this. I'm assuming your concern is that it will also affect other objects with this material applied to it. I intend for this object to have a unique material, BUT I will follow your advice and just make a new one for the instances when I want friction to change through an OnTriggerEnter or OnCollisionEnter event.
Well, the rest is up to you, and sometimes it is ok to do "bad stuff" in the right context. Don't forget to accept the answer if your problem is solved :)
Thanks to Xelareip, I have adjustd the jumpHeight value to a more appropriate level and removed Time.deltaTime from the velocity assignment. According to my team members, this satisfactorily solved the problem we were experiencing. During my own testing, I noted that using Xelareip's advice of lowering friction on the player collider and adjusting the friction combine to minimum would also provide a satisfactory solution.
– coptout