Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 affir$$anonymous$$g 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.

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

2D Detect collisions of a 2D block only on left/right (not top/bottom) 0 Answers

How can I make an object stop all momentum and hold it's position in air? 1 Answer

Why didnt my Collider works? 0 Answers

Why is there a gap between my player and the wall during wall slide? SOLVED 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges