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?

Current Code on Mario

if (other.tag == "Start Camera Trigger"  Input.GetKey("right")) { cameraFollow.cameraFollowZ = true; }

On the camera

if (Input.GetKey("left")  !Input.GetKey("right")) cameraFollowZ = false;

Current Code on Camera

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.

*Note this is a repost of a unity question in UnityAnswers that doesn’t seem to warrant more then one answer :frowning:
http://answers.unity3d.com/questions/342834/platforming-collision-help.html#answer-344149

i foresee performance issues in your future my friend…

Anyway.
for your first issue, you really shouldn’t be playing with an objects transform if your using physics. I’m not sure how everything is setup for you so you may not be using the physics the same way i’m thinking you are. Mario ends up through the floor – this is called tunneling. I think there’s an option to toggle on the rigidbody (assuming your using one…) where you can set the collision to be continuous and dynamic as well as making sure static objects remain as static colliders. Otherwise you can look up a bullet script to see how to make custom collision for your may-re-oh character.

for your second issue, you can make the script to a SendMessageUpwards( typeSomeParentFUnctionNameHere, SomeParameterYouWIshTOPass, SendMessageOptions.DontRequireReciever ); and the parent of the head can capture that message by defining a function in a component script as typeSomeParentFUnctionNameHere. You should probably investigate the documentation on the Monobehaviour class for this. I understand you hate having too many scripts, get used to it though. :smile:

I don’t think i understand what your saying with the camera stuff at the bottom.

Care to elaborate I am not beyond being told your doing it wrong. Sadly the class I took that involved Unity was very um… basic my hopes is to learn to use it properly and spread that knowledge to the teachers so that the class becomes much more useful.

Collision in general are giving me a headache the only reason I used a rigid body was because it seemed the only thing that activated the triggers on my floors which I wouldn’t need if it actually just collided with the floor. I should explain that I am not using a character controller (for better or worse?) Mainly because I felt like using it was cheating myself out of learning how to actually code proper movements, but I’m starting to think their is more to it then just how it works controls. I will try changing the collision detection to continuous or something else and see if that fixes it.

I will definitely be looking into this, I’m figuring right now I should get the collision working right which will give me less of headache having to deal with enemies getting hit and focus more on how it should work then. If I use SendMessage function it should work right then (in theory), not sure if I need to make the script separate or not in order for it to work, but if it works w/e

I don’t mind making scripts, I just feel like it would be a performance issue to have so many script on each different thing. I feel like a script should be able to interact with anything attached to it.

Basically I replicated the Mario cam from the game it only follows you if your at a certain point to the right and hold right otherwise it stops follow (like it the original Mario) the way I do it is a invisible trigger is attached to the camera that detects Mario and checks to see if the player is holding right if it is it moves with him. The problem I am getting is that if I hit right, left, right quickly I can sneak through the trigger and thus the camera doesn’t follow me. I’m not sure how to fix this.

Also tags, is it normal to have lots of them? Also thanks for the reply.

Hmmm seems to be UnityAnswers syndrome in here :\

Don’t worry about the performance stuff for now, worry about that when (read if) you notice stutters in gameplay or just terrible FPS when playing.

The only real advice I can give to you for physics is that your going to have to keep working with it and perfecting it. I may have written my own physics engine before, but playing with unity physics was a totally different beast. Same idea as taking forever to get Box2D physics working properly. It took me a while to get a ball to bounce around a playing field properly, that is even with the degree of error unity uses to fake certain values. I wish i could suggest a book on this that relates to Unity but i can’t think of one off the top of my head. I know there are some tutorials out there you can find that show some more interesting things dealing with physics that you might find useful though.
Anyways, you can go into the physics settings and either increase the rate at which physics runs and the amount of precision it will use to determine values. That may help solve some of your issues. IF your using any code that runs in scripts, try putting them in the FixedUpdate function instead of an Update() function. FixedUpdate relates to physics in scripting so that may help you as well.
I can’t get into much more detail than that as i don’t think i’ve used Unity physics enough to say much more. But remember that the physics here is probably worth 80% of your game, so its worth the time to get it right so it “feels good” over just about anything else.

The character controller was written because Human Interaction with the computer is terribly difficult to program effectively, but its mostly designed to show you how to work things and the complexities of a controller script since i don’t think it fits well for just about anything without quite a bit of extra work involved.

Now for the camera, i think unity gives you a SmoothFollow script for a camera. It’s probably a better idea to allow the camera free movement while only limiting the character. I think your setup for this is already there but coding it will yield plenty of bugs for you to solve. IE: you only need a right trigger to activate smooth following of the character, a character exiting the right side of the screen should stop the smooth follow and the character should be stuck on screen. I believe thats how it works right?

The questions is, do you need the character controller to get proper collisions? I’ve been using just simple empty game object that contains the character and the script moves that -x or +x and jump for y etc. The problem I having is getting this to detect the floor, I’ve been using triggers that set the character’s y to a default position when it hits it, but this is now causing problem with enemies because the trigger sets off the death animation even when they hit Mario. I really just want collision, but I just can’t get it to work for some reason.

The camera works fine, its just that right now you can trick it if you stand next to the invisible trigger and hit left then right quickly and you pass right through it.

I’m trying to fake physics is it possible to use collisions with “is Kinematic” not being checked? The only way I can get hit detection to work is triggers, the problem with triggers is that two objects with triggers don’t collide which is a problem when you have a character that can be hit and can hit other things. Also I cannot for the life of me figure out a way to get the engine to find the Gameobject the collider is connected to this seems like it would be a much simpler thing, the problem is technically the extra collider is another game object as I can’t figure out a way to add more then one collider otherwise.

Heres an example of what I am trying to do right now: Mario → Steps On Goomba —> Goomba Dies/Mario jumps slightly.

Collision should happen when the Goomba detects Mario hitting his head this only happens if the gameObject with no mesh and a collision box on it name GoombaHead is set as a trigger and Mario detects this trigger, I get Mario to jump, but the animation is on The Goomba Gameobject itself, not the Collision box name Goomba Head, so now what? Make the main hitbox the head and use the rest of the body for collision? Whatever collision box is not directly connected to the main game object basically does nothing and it’s pissing me off.