Plethora of Questions (Collisions give wrong names. imitating Crossy Road movement, is this expensive performance-wise, how would I lerp a small jump like in Crossy Road?)
Hello Unity3D community,
I have been having problems with detecting the correct collision. Basically, the game I am currently working on consists of a map. This map has different game objects parented to it (these make up the grid.) You can see this here. However, because I think I need to linearly interpolate (using Mathf.Lerp) the players jump from box to box, I need to find the name of each box. I have tried to do this by doing the usual collision detection using a Box Collider:
public string positionName;
[SerializeField]
private bool grounded;
void OnCollisionEnter(Collision col)
{
grounded = true;
positionName = col.gameObject.name;
}
void OnCollisionExt(Collision col)
{
grounded = false;
}
However, when I run the game using the Unity Editor, I don't seem to get the results I expected. The variable col seems to be giving the wrong object name. For example, if the player is standing on prism C2, the collider returns D2 instead. You can see this here. I've tried other techniques like using the contact points, or changing the grid into kinematic rigidbodies, and declaring col.gameObject.rigidbody.name
, but none of the methods are working. I would really appreciate any help with this.
I am open to options for finding a way to get a (Crossy Road like) movement system working, as I am having a problem with that in general. I'm also open to options on finding out what the name of the prism the player is standing on, and finding what the prisms on the left/right/backwards/forwards are called. Keep in mind that this is mobile game - so performance is really key.
I'm truly stuck and bundled with questions; I would appreciate any help I can get from the community.
Thank you so much,
8Development
Your answer
![](https://koobas.hobune.stream/wayback/20220612082247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Platformer Character Acts Weird When Collide Side of a Platform 0 Answers
Detecting missing collision in 2D platformer to change direction for enemy - without Raycast 1 Answer
How do I make tiles that light up when gameobject touches them? 0 Answers
How can I make an object moving on its own bounce off walls 1 Answer
Bugs on move in air(falling); 0 Answers