So I recently started working on a simple 2d side scroller, but I have com across an issue with Rigid Body 2D physics and 2D Colliders.
I have a script for jumping that checks for a standing state in a Collision Layer script. If standing is true then you can jump by keeping the current X velocity of the Rigid Body, and applying a jump speed in place of the y velocity. However, when tested in unity, when the jump button is pressed, the player will lock and place and can no longer move.
The box/sphere Colliders themselves seem to be doing this weird thing where they partially sink into each other; the green lines that indicate the size of the collider isn’t where the colliders “collide”
Here is the code for the jump script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : AbstractBehavior
{
public float jumpSpeed = 200f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
var canJump = inputState.GetButtonValue(inputButtons[0]);
if (collisionState.standing)
{
if(canJump)
{
OnJump();
}
}
}
protected virtual void OnJump()
{
var vel = body2d.velocity;
body2d.velocity = new Vector2(body2d.velocity.x, jumpSpeed);
}
}
This is what I mean by the colliders partially sinking. The red circle is a debug circle for finding the point to check whether the player is standing or not (collision with layer that the ground is in). Any help is appreciated.
