Hi,
Im trying to make a simple fast paced 3D plat former to learn the basics of unity. I wish to implement a wall jump that is relative to the surface the player is standing on so i dont have to create many diffrent implementations of what the player is standing on. This is my script so far…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
public float jump = 20f;
private Rigidbody rb;
float timer = 0.0f;
bool isGrounded = true;
void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
bool player_jump = Input.GetButtonDown("Jump");
if (player_jump && isGrounded)
{
rb.AddForce(Vector3.up * jump);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
if (collision.gameObject.CompareTag("Wall"))
{
isGrounded = true;
}
}
void OnCollisionExit(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = false;
}
if (collision.gameObject.CompareTag("Wall"))
{
isGrounded = false;
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}
So, My player is a ball and i wish to have it able to wall jump off of a wall. For now it jumps only up and i want to be able to grate a jump that applies a force off the wall. Like in Mario. So how do i create a wall jump that is relative to the surface that the player is standing on?