Falling platforms

Hi, i have just began using unity3d and c#, i need the most simple script for making a platform fall when colliding with “player”

because mine doesn’t seem to work?..
Thank you!

What you are doing in your script does look like it should work. Setting isKinematic to false should allow the platform to be affected by physics, and thus fall due to gravity. The problem is more likely in how your scene is set-up. I would check that you have that rigidbody set so that gravity affects it, and that no colliders are below it blocking its path and that it has an appropriate amount of mass etc

Have you put a debug line after the change of kinematic or watched in the inspector to see if the flag is turning off?

Yep the gravity is set and no colliders blocking it, its not turning false when my player collides with it, the error code is:
Object reference is not set to an instance of an object, then if i click the error it highlights the rb2.iskinematic = false; part in the script

Do i need to tell the script that IsKinematic is True in the start void or awake void to make it understand?

Let me Google that for you. :wink:

Seriously though, check the MonoBehaviour method docs for the correct capitalization of these callbacks; it should be ‘Awake’ not ‘awake’.

In the future, I would also recommend using Debug.Log or placing breakpoints to check that code is being executed.

Hope that helps.

1 Like

Thanks man, it was the capital A… hahah

another question, i have an edge collider which is the Trigger for the platform fall, and i have a box collider2d for (with oneway effector) to be able to stand/jump from the platform, but this creates another issue of mine, the fallDelay counter starts when I’m jumping through the platform, not when i land on it so to say, maybe you know how to fix that to ?

Do some raycasting upwards to check for the player instead of relying on the collider?

You can do this with your edge collider as reference, get the length of that collider, then raycast from regular intervals along it, then trigger your timeDelay when one of those rays hits the player and the hit distance is below a certain value (or is just 0).

If you look up Sebastian Lague on YouTube he has a very nice series of tutorials on making 2D platformers that explains this method very well.

It’s not the simplest method, but it is absolutely bomb-proof.

1 Like