Collision detection against piled objects is buggy
I have a 1x1x1 cube for most of my objects, with many prefabs that mostly only change textures for their cube. The camera and movement however are on 2-d, making a side scroll platformer (yup, I'm ripping off Mario as a learning project).
When I jump to a wall that is composed of a number of piled objects, the player object (also a cube...) can "press" into the wall to stick to it until he stops trying to move into it. I doesn't happen when it is a single object forming the wall and I tried creating a physics material with no attrition with no success. Tried using box and mesh colliders and adding a rigidbody to the wall objects too, the player can still push into the wall.
Found a workaround by selecting the piled cubes and merging them to a single object, then reconfiguring the box collider. Now that it is a single box collider, the player can't push into the meshes anymore.
Still interested in any input as to why the collision was working like that in the case of adjacent objects
Answer by xxmariofer · Jun 17, 2020 at 06:55 PM
thats probably because you are using the transform to move the player, try moving the player using the rigidbody.velocity for example and see if that works for you
Answer by XikoNorris · Jun 17, 2020 at 07:22 PM
I'm moving using the rigidbody.moveposition function, but I'm using script defined velocities to have a running and a walking speed. This is my move code:
public float m_MoveSpeed;
public float m_RunSpeed;
private bool m_IsRunning;
private Vector3 m_Movement;
private Rigidbody m_Body;
void Start()
{
m_Body = GetComponent<Rigidbody>();
}
void Update()
{
m_Movement.x = Input.GetAxis("Horizontal");
if (Input.GetButtonDown("Fire1")) m_IsRunning = !m_IsRunning;
}
void FixedUpdate()
{
Move();
}
private void Move()
{
float speed = m_IsRunning ? m_RunSpeed : m_MoveSpeed;
m_Body.MovePosition(m_Body.position + m_Movement * speed * Time.fixedDeltaTime);
}
Found a workaround by selecting the piled cubes and merging them to a single object, then reconfiguring the box collider. Now that it is a single box collider, the player can't push into the meshes anymore.
Still interested in any input as to why the collision was working like that in the case of adjacent objects.
Your answer
Follow this Question
Related Questions
Detect Collision of non-trigger- and trigger-colliders 1 Answer
Unity setting my Player to not active randomly 0 Answers
fbx collision with cube with physics 0 Answers
How to make rigidbody static ? 0 Answers
Ball won't stop bouncing 1 Answer