Hey guys, my character jumps just fine, until he moves onto a new ground platform which is directly connected to the original one, then he stops jumping all together, regardless if I go back to the old ground platform.
Here is my movement script
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float MoveSpeed;
public float UpSpeed;
public float shiftSpeed;
public float stamina;
bool grounded = true;
bool running = false;
// Update is called once per frame
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground")) { grounded = true; }
if (collision.gameObject.CompareTag("PlatformMoving")) { grounded = true; }
}
public void OnCollisionExit(Collision collision)
{
if (collision.gameObject.CompareTag("Ground")) { grounded = false; }
if (collision.gameObject.CompareTag("PlatformMoving")) { grounded = false; }
}
void FixedUpdate() //for updating physics
{
Physics.gravity = new Vector3(0, -150f, 0);
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, MoveSpeed * Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("s"))
{
rb.AddForce(0, 0, -MoveSpeed * Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("a"))
{
rb.AddForce(-MoveSpeed / 56, 0, 0 * Time.deltaTime, ForceMode.VelocityChange);
}
if (Input.GetKey("d"))
{
rb.AddForce(MoveSpeed / 56, 0, 0 * Time.deltaTime, ForceMode.VelocityChange);
}
if (rb.position.y < -5f)
{
FindObjectOfType<EndGame>().gameover();
}
if (Input.GetKeyDown ("left shift"))
{
MoveSpeed = shiftSpeed;
running = true;
}
if (Input.GetKeyUp("left shift"))
{
MoveSpeed = 105f;
running = false;
}
if (running == false && stamina < 8f) { stamina = stamina + 2 * Time.deltaTime; }
if (running == true && stamina > 0f ) { stamina = stamina - 6 * Time.deltaTime; }
if (stamina < 1f) { MoveSpeed = 105f; }
if (stamina != 8f) { shiftSpeed = MoveSpeed; }
if (stamina >= 1f) { shiftSpeed = 155f; }
}
public void Update()
{
Physics.gravity = new Vector3(0, -150f, 0);
//not firing consistently in fixedupdate
if (Input.GetKeyDown("space") && grounded)
{
rb.AddForce(0, UpSpeed, 0 * Time.deltaTime, ForceMode.VelocityChange);
}
}
}
I have also attached a picture so you can see the two grounds platforms connecting.
Both have tags set to “ground”
There are other ground platforms and moving platforms and I’ve not had any issues with those.
EDIT: Just checked now that If I jump between the first and second ground platforms, I can still jump. But If I move my character normally between the platforms, that’s when jumping stops all together.
Any ideas how to fix this? I’d like both ground objects to be touching and looking like one whole platform.
Thanks in advance!