Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Jun 06, 2019 at 09:56 AM by adovehv for the following reason:

Other

avatar image
0
Question by adovehv · Jun 04, 2019 at 11:21 AM · movementplayerphysics2dhole

Move player position a bit

Hi!, i'm make a hole in my game, when the player has fallen for this hole, appears in the same position, i want my player appears a bit far of this last position so that it does not fall back through the hole again, how could I do this?, now i have this code, thanks.

Video to understand it better: https://www.youtube.com/watch?v=cq76T0ws47Q

 //Falling Hole
     private void OnTriggerEnter2D(Collider2D col)
     {
         if (col.CompareTag("hole"))
         {
             print("falling");           
             CallFallingCoCoroutine();
         }
     }
    
     public void CallFallingCoCoroutine()
     {
         StartCoroutine(fallingHole());
     }
 
     //Falling hole coroutine
     float fallSeconds = 0.5f;
     float flashHoleDelay = 0.2f;
     public IEnumerator fallingHole()
     {
         Health.Instance.health--;
         anim.SetBool("falling", true);
         canMove = false;
         rb2d.constraints = RigidbodyConstraints2D.FreezePosition;
         yield return new WaitForSeconds(fallSeconds);
         anim.SetBool("falling", false);
         canMove = true;
         rb2d.constraints = RigidbodyConstraints2D.None;
         yield return new WaitForSeconds(flashHoleDelay);
         vulnerability = true;
         CallFlashCoCoroutine();       
     }

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
0

Answer by Magso · Jun 04, 2019 at 01:20 PM

You can start the coroutine from OnTriggerEnter2D. I'm gathering that the animation is the fall itself rather than using the rigidbody, in this case you can use transform.Translate(Vector3.back*holeWidth) just after anim.SetBool("falling", false)

Comment
Add comment · Show 2 · 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 adovehv · Jun 04, 2019 at 01:59 PM 0
Share

Hi!, i use this but not work, the player not move back.

  //Falling Hole
     private void OnTriggerEnter2D(Collider2D col)
     {
         if (col.CompareTag("Player"))
         {
             print("falling");
             CallFallingCoCoroutine();
         }
     }
 
     //Call falling coroutine
     public void CallFallingCoCoroutine()
     {
         StartCoroutine(fallingHole());
     }
 
     //Falling hole coroutine
     float fallSeconds = 0.8f;
     float flashHoleDelay = 0.2f;
     public IEnumerator fallingHole()
     {        
         anim.SetBool("falling", true);
         can$$anonymous$$ove = false;
         rb2d.constraints = RigidbodyConstraints2D.FreezePosition;
         yield return new WaitForSeconds(fallSeconds);
         anim.SetBool("falling", false);
         transform.Translate(Vector3.back * 2.5f);
         can$$anonymous$$ove = true;
         rb2d.constraints = RigidbodyConstraints2D.None;
         yield return new WaitForSeconds(flashHoleDelay);
 
         if (vulnerability == false)
         {
             Health.Instance.health--;
             CallFlashCoCoroutine();
         }       
     }

avatar image Magso adovehv · Jun 04, 2019 at 03:49 PM 0
Share

Sorry I've just realised you're working in 2D, it should've been Vector2.left or Vector2.right.

avatar image
0

Answer by RustyCrow · Jun 04, 2019 at 02:46 PM

Edit: after watching the video OP provided in the comments, the only way i know from the top of my head would be a respawn position. create a empty gameobject in the scene(This will be your respawn position) at the end of the falling code you set
player.transform.position = respawn.transform.position.

For now you can just make a Public Gameobject RespawnPoint in the Falling script and drag and drop the point in the inspector. This will snap the player to the empty gameobject position. However if you want to spawn him next to the Hole from the position he went in then i dont have a answer atm sorry.

Comment
Add comment · Show 3 · 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 adovehv · Jun 04, 2019 at 03:22 PM 0
Share

Hi! Yes, it's a 2D game. I don't need instantiate the player because he not desapear, i have two colliders, the player collider and the hole collider, when the player touch the hole collider, the code above work, but when the code is finished, i want move the player a bit out of hole, I leave a video so you understand it better, thanks :)

https://www.youtube.com/watch?v=cq76T0ws47Q&feature=youtu.be

avatar image RustyCrow adovehv · Jun 04, 2019 at 04:36 PM 0
Share

Thank you for video, i understand now. I will edit the answer but i dont think i can give you the answer you want. Its a little to complex for me to think about on the fly. Edit your question with the video link its helps alot.

avatar image adovehv RustyCrow · Jun 04, 2019 at 04:45 PM 0
Share

Yes, It's a bit complicated, thank you anyway :)

Follow this Question

Answers Answers and Comments

179 People are following this question.

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

Related Questions

Player stops moving upon collision 0 Answers

I want to make a pull shoot system like glass pong game but i am enable to do so can someone help me with the scripting please,want to make a pull shoot system like glass pong game please help 0 Answers

My Player is crossing the ground through air 1 Answer

How to Logically Match Ground Slope While Using This Code? 1 Answer

Move player in a cyclic path? 0 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