Greetings,
I’m making a 2D platformer. I’m using 3D physics in it (100% 3D physics, no mix). The problem is that when the player jumps from a ground to another, occasionally the character hits the side of the platform. In these cases the character gets sticked to the side (until I let the move button go). Either way this makes the gameplay unbearable. How to solve this? I’m using this as reference where the tutor faces this issue as well by the way.
My platforms are 3D boxes, my character is a 3D capsule. Everything else I used like in the tutorial I posted.
I would perefer the player to slide up to the box if that’s possible, if not, killing the character is fine as well.
All the help appreciated.
Some code: my character movement:
void Start ()
{
//in dev: setting the pos so I don't have to play it over again.
gameObject.transform.position = new Vector3(47.1f, -4.18f);
//
jump = true;
moveForce = 36.50f;
maxSpeed = 8.0f;
jumpForce = 1000.0f;
grounded = false;
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
grounded = Physics.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
if(Input.GetButton("Jump") && grounded)
{
jump = true;
}
}
void FixedUpdate()
{
//constant movement forward. needs to be updated because of the fall.
Moving();
}
void Moving()
{
float h = Input.GetAxis("Horizontal");
rb.velocity = new Vector3(maxSpeed * h, rb.velocity.y);
//if(h * rb.velocity.x < maxSpeed)
//{
// rb.AddForce(Vector3.right * h * moveForce);
//}
//if (Mathf.Abs(rb.velocity.x) > maxSpeed)
//{
// rb.velocity = new Vector3(rb.velocity.x * maxSpeed, rb.velocity.y);
//}
if (jump)
{
//anim.SetTrigger("Jump");
rb.AddForce(new Vector3(0.0f, jumpForce));
jump = false;
}
}