- Home /
Can't Jump when running against a wall..?[Not solved]
I have a Rigidbody attached to my character and I tried to use Physics.velocity or Physics.addforce to jump but when I was running against a wall I couldn't jump anymore only when I let go of the moving joystick. I guess it is because I'am adding force up aswel as forward so he wil 'scrub' the wall causing himself not to jump..? Is there a way to solve this besides using a CharacterController? Thanks in advance. btw I also tried "rig.AddForce(transform.up * jumpHeight, ForceMode.Impulse);"
If it's problem with wall friction you can experiment with physic material on your colliders
Answer by mike29willems · Mar 13, 2019 at 01:45 PM
If I use Transform.translate for jumping, it wil still go up when running against a wall but it will not go with physics so it looks silly. Anyone has an idea? @Vollmondum
There's always ideas :) You will be 100% right if you disregard native engine physics. In my games I write my own physics all the time. You know school formulas Set 3 variables: jump height, jump$$anonymous$$axSpeed, and acceleration, maybe jump duration and distance if you want complexity. Two simple lines of code make your char jump without any other "wind, gravity, side effects, drag, collistion etc" useless forces. So:
if(transform.position < jump height max)
{
translate up, jumpSpeed;
characterSpeed = jumpSpeed;
characterSpeed -= acceleration;
}
else
{
translate down, jumpSpeed;
characterSpeed = 0;
if(characterSpeed < jumpSpeed)
{
characterSpeed += acceleration;
}
}
etc.
Answer by Vollmondum · Mar 13, 2019 at 01:23 PM
Make sure your character's collider is NOT a box, should be either sphere or capsule. Box has sharp corners that eventually "stick" into that wall, thinking it's a ceiling
Another reason is gravity. If your models are too large, you won't notice the jump. Go to settings->physics and decrease gravity, or scale your models down
It worked when I $$anonymous$$ade a physical material and set the friction to null. Thank you for ur help! @Vollmondum
Answer by CCnockaert · Mar 12, 2019 at 03:17 PM
Can you share your code please, and maybe a screenshot of your scene ? I guess your character collides with the wall, so the base physics engine reduces the force applied to your char.
yeah how can u prevent the base physics engine to reduces the force applied or override it.
void Start() { playerRig = GetComponent(); anim = GetComponent(); } private void FixedUpdate() { h = Joystick.Horizontal; v = Joystick.Vertical; $$anonymous$$ove(h, v);
}
private void $$anonymous$$ove(float h, float v)
{
movement.Set(h, 0f, v);
if (movement != Vector3.zero)
{
Quaternion newRotation = Quaternion.LookRotation(movement);
playerRig.$$anonymous$$oveRotation(newRotation);
}
movement = movement * speed * Time.deltaTime;
playerRig.$$anonymous$$ovePosition(transform.position + movement);
public void Jumping() {
if (IsGrounded)
{
rig.AddForce(transform.up * jumpHeight, Force$$anonymous$$ode.Impulse);
}
$$anonymous$$aybe the value of jumpHeight
is not big enough, in order to apply an adequate amount of force upwards. $$anonymous$$aybe you could try experimenting with larger values to see what happens.
the problem is then that my normal jump will get to high
Your answer
Follow this Question
Related Questions
When stopping Rigidbody.velocity 1 frame stutter C# 0 Answers
Cannot move and jump with rigid body. 0 Answers
Gameobject going past target when using rigidbody2d.addforce 1 Answer
How can i initiate an object in parabolic motion without using gravity using Rigidbody2D? 1 Answer
How to allow the player to change the mass/force of an object in the UI? Noob question 2 Answers