Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Falling platforms

Discussion in '2D' started by EmilKihlberg, Oct 28, 2015.

  1. EmilKihlberg

    EmilKihlberg

    Joined:
    Oct 28, 2015
    Posts:
    11
    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! Skärmavbild 2015-10-28 kl. 18.42.38.png
     
  2. VorpalSilence

    VorpalSilence

    Joined:
    Oct 22, 2015
    Posts:
    13
    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
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Have you put a debug line after the change of kinematic or watched in the inspector to see if the flag is turning off?
     
  4. EmilKihlberg

    EmilKihlberg

    Joined:
    Oct 28, 2015
    Posts:
    11
    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?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,557
    Let me Google that for you. ;)

    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.
     
    SAOTA likes this.
  6. EmilKihlberg

    EmilKihlberg

    Joined:
    Oct 28, 2015
    Posts:
    11
    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 ?
     
  7. Prototypetheta

    Prototypetheta

    Joined:
    May 7, 2015
    Posts:
    122
    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.
     
    Last edited: Oct 29, 2015
    theANMATOR2b likes this.