• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SirAlfi · Dec 08, 2015 at 11:57 AM · 2d2d game2d-platformer2d-physics2d platformer

Problem with Falling Platform Script

So I basically watched GucioDev's video for the tutorial about falling platform. Here is the video

but however, for some reason I'm not able to get it working. Here is the script that I used to test it out (same script just like in the video but without "GetComponent().isTrigger = True;" part)

The Script:

using UnityEngine; using System.Collections;

public class FallingPlatform: MonoBehaviour {

 private Rigidbody2D rb2d;

 public float FallDelay;

 void Start ()
 {

     rb2d = GetComponent<Rigidbody2D>();

 }

 void OnCollisonEnter2D (Collision2D col)
 {

     if (col.collider.CompareTag("Player"))
     {

         StartCoroutine(Fall());

     }

 }

 IEnumerator Fall()
 {

     yield return new WaitForSeconds(FallDelay);
     rb2d.isKinematic = false;

     yield return 0;

 }

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jawadov · Mar 11, 2016 at 02:49 PM 0
Share

Hi SirAlfi , do u find any solution for that its not working for me tow .

avatar image RSharma98 · Aug 26, 2016 at 12:20 PM 0
Share

I just realised you spelled "OnCollisionEnter2D" incorrectly. Fixing that will make your code work correctly

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by RSharma98 · Aug 26, 2016 at 11:11 AM

It should be: StartCoroutine("Fall");

Rather than: StartCoroutine(Fall());

Hope that helps

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hellium · Aug 26, 2016 at 11:18 AM 0
Share

Read the documentation before affirming something :

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.StartCoroutine.html

avatar image RSharma98 · Aug 26, 2016 at 11:33 AM 0
Share

@Hellium. You can also use the method I suggested, scroll down on the page and you will see. I have been using this method for a while and this works perfectly fine

avatar image Hellium · Aug 26, 2016 at 11:47 AM 0
Share

Yes I know, but using the StartCoroutine with the string parameter :

  • Does not let you to keep a reference of your coroutine

  • Does not let you to refactor your coroutine

  • Does not let you to track where your function is called using your IDE

I don't know why Unity keeps this in the specifications

avatar image RSharma98 Hellium · Aug 26, 2016 at 12:21 PM 0
Share

Oh ok. I never knew that. Thanks for letting me know

avatar image
0

Answer by OncaLupe · Dec 09, 2015 at 07:44 PM

Code looks fine to me. Double check the player's tag is exactly "Player" with capital letter, gravity scale is set on the platform's rigidbody, and it's not set to freeze position under Constraints.

You can add some Debug.Log() to see exactly what is or is not running. For instance, put Debug.Log(col.collider.tag); at the top of the OnCollisionEnter2D to see what (if any) is being collided with. Probably another Log inside the if() and in the Fall() method to make sure it's starting.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with 2D movement. My character is moving by himself between two points... :) 1 Answer

simulate gravity in a 2D game 3 Answers

Level design clone of King of Thieves 0 Answers

Jumping from special jump orb 1 Answer

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges