How do I make one object stick to another?
I'm trying to make a 2d platformer, and want to make the player able to jump on enemies. To do this, I've given an empty object (also used for ground detection) under the players feet. The idea is that whenever this empty object (witch has a 2d rigid body and collider) touches an enemy, it'll defeat it.
The problem is, while the object will follow the player horizontally, it won't vertically. So if the player jumps, and the enemy walks under them, the object will touch the enemy and defeat it. What am I doing wrong?
Answer by mephistoII666 · Aug 28, 2020 at 01:06 AM
If an object has a dynamic rigidbody (one that is not kynematic or static) it is entirely subject to the physics simulation, independently of the parent.
If you want a collider to follow tightly your player character, the "shoe" gameobject must NOT have a Rigidbody2d.
You must place your Rigidbody2D on the parent (the player), and add a Collider2D to the "shoe" gameobject.
It will then be a child collider of the player character rigidbody.
Your answer

Follow this Question
Related Questions
Enemy ragdoll 0 Answers
Projection that detects first hit and stops 0 Answers
Raycast inconsistent 1 Answer
How do I calculate the angle between where an entity is facing and a target. 2 Answers