- Home /
Character stucks always (Rigidbody/Character)
Hello there,
i am working on a 2D-Platformer-Game and i am struggling with the Physics of the game.
So, we built the level with the cool "Uni2D"-PlugIn and gave the plattforms convex physics with the PlugIn-Feature, and set the "Edge Simplicity" to 1, so the collider is kind of "pixel-by-pixel".
The Problem is the Main Character. I really tried to, but i didn't manage to work it out with Character Controllers or Rigidbodys, here is the thing ( i made some poorly drawn pics):
Think of it as the first plattform, and think that the whole plattform is a collider.
So, here is the character, and i managed to move him quite well around on the ground. BUT:
When i jump, the Character is stuck at the Cliff/Corner, then, i have to jump again, and sometimes, i just press to the right and he kind of flies away. This is the behaviour with an Character Controller.
I also tried to do it with a Rigidbody + BoxCollider/SphereCollider/CapsuleCollider. Nearly same results, but the BoxCollider is the worst, it just goes THROUGH the ground.
Here is the script i used (for the CharController-Version):
using UnityEngine;
using System.Collections;
public class charControllerMovement : MonoBehaviour {
public float speed = 10.0f;
public float jumpForce = 10.0f;
public float gravityForce = 20.0f;
public CharacterController controller;
//the direction we are going to move
private Vector3 dir;
void Start()
{
//load a reference to our character controller component
controller = GetComponent<CharacterController>();
}
void FixedUpdate () {
//is the user pressing left or right on the keyboard?
dir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//transform direction to local space
dir = transform.TransformDirection(dir) * speed;
//apply gravity
dir.y = controller.velocity.y - gravityForce * Time.deltaTime;
//are we jumping?
if (Input.GetKey("space"))
{
dir.y = jumpForce * gravityForce * Time.deltaTime;
}
//move our character
controller.Move(dir * Time.deltaTime);
}
}
I really don't know how to handle this behavior, and would be really really grateful if someone could give at least a hint how i could manage that.
Did you try to use slope and step offset ? for example i use 90 degree for slopelimit you can change this by experiment controller.slopeLimit = 90; controller.stepOffset = 0.7;
Your answer
Follow this Question
Related Questions
2D rigidbody movement & walls 2 Answers
Making character dash forward 0 Answers
C# Need Help converting from Rigidbody to Character Controller 0 Answers
A node in a childnode? 1 Answer