- Home /
Question by
MidgardDev · May 15, 2013 at 06:32 PM ·
collisionmovementrigidbodyboxcollider
Box collider (with Rigidbody attached) gets stuck into another Box Collider
Hi there, I'm having some problems by moving a box collider with a rigidbody attached to it through another Box Collider, just like a Player moving on top of a platform, the problem is that it gets like inside of the platform collider, it's strange and 'cause of it it slows the Player instead of adding speed, I did search for a solution but I didn't find anything. There's an image of what I'm saying:
And there's my own movement script (still in development):
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float normalSpeed;
public float maxSpeed;
public float jumpForce;
public bool isOnGround;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
print(rigidbody.velocity.magnitude);
if (rigidbody.velocity.magnitude > maxSpeed)
{
rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
}
if (Input.GetKey("left"))
{
rigidbody.AddForce(-normalSpeed, 0, 0);
}
else if (Input.GetKey("right"))
{
rigidbody.AddForce(normalSpeed, 0, 0);
}
if (Input.GetKeyDown("up"))
{
if (isOnGround == true)
{
rigidbody.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
isOnGround = false;
}
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "ground")
{
isOnGround = true;
}
}
}
I'll be looking for answers, and possibly a solution. Thankyu.
Comment