- Home /
resolved my issue
3D wall jump almost working
So I've been trying to make a wall jump for my game for a while now, and nearly found a solution. With this script, you can detect when a wall is near you, where the wall is and when you press the space bar It shoots you up and the direction the wall is facing. The problem is that when you actually do wall jump it's almost instant as if you teleported. Any suggestions or possible fixes? Any answers are appreciated.
Movement Script:
void FixedUpdate() {
moving = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D);
if (moving)
{
transform.localRotation = Quaternion.Euler(0, Camera.rotation.eulerAngles.y, 0);
}
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
Vector3 move = (transform.right * x + transform.forward * y);
move.Normalize();
rb.velocity = new Vector3(move.x * speed * Time.deltaTime, rb.velocity.y, move.z * speed * Time.deltaTime);
onGround = Physics.CheckSphere(new Vector3(transform.position.x, transform.position.y - 1, transform.position.z), spSize, Environment);
}
Wall Check:
private void CheckForWall() // called every update { isWallRight = Physics.Raycast(transform.position, transform.right, 0.73f, Environment);
if (isWallRight)
{
wallJump = -transform.right * jumpForce;
canWallJump = true;
Debug.Log("Right Wall");
}
isWallLeft = Physics.Raycast(transform.position, -transform.right, 0.75f, Environment);
if (isWallLeft)
{
wallJump = transform.right * jumpForce;
canWallJump = true;
Debug.Log("Left Wall");
}
if (!isWallLeft && !isWallRight)
{
canWallJump = false;
}
}
And finally the wall jump:
private void WallJump() { rb.AddForce(jump 15, ForceMode.Impulse); rb.velocity = Vector3.zero; rb.AddForce(wallJump wallJumpForce, ForceMode.VelocityChange); speed = jumpSpeed;
void Update() { rb.AddForce(0, -gravity * Time.deltaTime, 0);
CheckForWall();
if (Input.GetKeyDown(KeyCode.Space) && onGround == true)
{
speed = jumpSpeed;
onGround = false;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
if (Input.GetKeyDown(KeyCode.Space) && canWallJump && moving)
{
WallJump();
}
}
}
Answer by Quazaar_studios · Jan 22, 2021 at 09:22 PM
No matter how you change the speed, it teleports? Have you tried that?
Nope ive tried setting the speed to 1 but it still doesnt work
Try setting it to an even smaller float, like .1 or .001, maybe your velocity is so high you see the player as if it teleported.
Follow this Question
Related Questions
How do I make a rigidbody 3D wall jump? 1 Answer
How do I make a Rigidbody 3D wall jump? 1 Answer
Rigidy body 3d wall jump 0 Answers
problems setting up wall jump 1 Answer