Platforming Collision Help

I’m having some issues with my Mario clone game.
First I don’t like the way my ground detecting works right now because I feel like it slows the character down when he lands, maybe its me, but here is an example of a collision on the floor.

if (other.tag == "Floor")
{
	transform.position.y = 3.028204;
	grounded = true;
		
	if (faceRight)
		animation.Play("IdleRight");
	else
		animation.Play("IdleLeft");	
}

Notice I transform the position to a specific y value a feel like for a split frame while its adjusting the y value the player is frozen, maybe I’m just imagining things. If I exclude this part of the script they stop, but many times it is later then I would like and Mario ends up through part of the floor or object he landed on.

Another issue I am running into is with floating blocks I have 3 collision box’s for each side of them and when I jump really close to the the side of one and hold into the box I get a lot of random results, either he hits it and bounces down (which is fine), gets stuck on the corner for a second and either pushed out or on top, or he teleports to the top (this is due to a similar collision as the floor that sets the y value.

I tried adjusting the collision box sizes, but nothing seems to work, maybe I should move the side boxes out more?

The second issue I have is with my enemies. Right now I have a hitbox on their head to my character to land on. This works fine, what I noticed was when I walked into them and died they still played their death animation. Turns out it was detecting if the hitbox from my character touched ANY of the collision boxs the enemy had. I only want it to do the head, since the script was attached to the actual enemy entity it does this, if I apply it to the head it doesn’t:

if (other.tag == "MarioFeet")

{

	gameObject.animation.Play("GoombaDeath");

	GoombaAIScript.move = 0;

	MarioMove.jumpSpeed = 0.3;

}

Since the script is on the actual object it plays the animation which triggers the destroy function in the events. The questions is how do I get the head collision box to detect the game object its attached to play the animation? Also is it possible to do this in a script not attached to the head? I hate having a script on so many different pieces of a character/enemy.

The third thing is the camera I made a script to follow Mario when he hits a collision box and is hold right the camera follows otherwise it stops. Problem is I am finding a lot of times where I clip through the collision box. I initially found if I held left first then right I would walk through it, I fixed this by making sure as long as left was being held to do it. Right now I can get through the collision if I fake it out by pressing left quickly then right. Any solutions?

Last questions not specific to collision, but is it normal to have a TON of tags? I have to have at least 50+ right now.

Anyway thank you for the help in advanced.

You’re going about this the wrong way .

For starters, it’s much simpler than that to get collision working. That y = 3 . . . Not a single clue why you would want to do that . . . Not unless you have very specific reasons. If you really really need the side boxes, set them to “trigger”, or, Physics.IgnoreCollision ( )

Example:

var bulletPrefab : Transform;
function Start () {
    var bullet = Instantiate(bulletPrefab) as Transform;
    Physics.IgnoreCollision(bullet.collider, collider);
}

Add a Box Collider and Rigidbody to your Mario player, and your collision issue should be fixed. It doesn’t take much for proper collision . If you already have colliders, you need to make sure that they are not set as “trigger”, have rigidbodies, and are positioned correctly.

Add this script to mario

function OnCollisionEnter ( collision : Collision )
{
   if ( collision.collider.tag == "Ground" )
   {
      grounded = true ;
   }
}

function OnCollisionExit ( collision : Collision )
{
   if ( collision.collider.tag == "Ground" )
   {
      grounded = false ;
   }
}

Secondly, maybe you have a specific purpose for the side boxes, but, I don’t really find them to be necessary from what I have read. . . And also, I don’t quite understand what’s going wrong on part 2 of your issue, but I will try my best to explain where you are going wrong. ( PS: Please bare with me if I am not understanding correctly )

I don’t see where you destroy the object after the animation is done. Perhaps add this Kill function ?

function KillEnemy ( )
{
   animation.Play ( "GoombaDeath" ) ;
   yield WaitForSeconds ( animation["GoombaDeath"].clip.length + 0.1 ) ;
   GoombaAIScript.move = 0;
   MarioMove.jumpSpeed = 0.3;
   GameObject.Destroy ( gameObject ) ;
}

For the third issue, I just can’t comment on without any sort of explanation as to what your code does, or, even better, a script that I can reference from.

I hope this answer solves your issues, and if so, please mark as answered/vote . Thanks for using Unity3D, and, best of luck to you sir/ma’am .

I’ve been messing with this for a while now I still can’t get it I don’t understand. Is it because I’m using a ridged body an is Kinetic for the character? If so what should I use?