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 Bioshok7 · Sep 13, 2017 at 09:11 AM · translationblocking

How to translate the platforms in the opposite direction as soon as they are blocked by solid objects?

Good morning ,

When the platforms sometimes translate they collide during their translation with the player or other solid game objects (with trigger false), I would like in these two cases that the platforms translate in the opposite direction as soon as they encounter a solid object or stop their translations and remain on site with possibility of translation later on in the opposite direction only .

how to implement please , the most ideal and correct solution for it?

Thank you very much ,

Cordially .

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

· Add your reply
  • Sort: 
avatar image
1

Answer by GenericToast · Sep 13, 2017 at 09:41 AM

You could attach a script like this to your platforms

 void OnCollisionEnter(Collision other)
 {
     if(other.gameObject.CompareTag("Platform") 
     {
         //Call a function in your platform translate script to change the translate direction
     }
 }

You can change the "Platform" tag to whatever object you want. These objects will cause the platforms to change direction after colliding with it. If your game is using 2D physics, just change "Collision" to "Collision2D".

If you only want the platforms to reverse direction if they collide from a particular direction, you can use other.contacts to get the point of contacts between the 2 colliding objects.

If you want both objects to stop before translating in the opposite direction, you could make a function like this in your platform translate script

 public void OnCollideWithOtherPlatform()
 {
     enabled = false; //This is to stop your platforms from translating
     Invoke("ContinueTranslation", 2.0f); //2.0f is the amount of time u want the platforms to stop for
 }
 
 void ContinueTranslation()
 {
     enabled = true;
 }

You would call OnCollideWithOtherPlatform() in the OnCollisionEnter function in the 1st script

Hope i understood your question correctly and that this helps!

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
avatar image
0

Answer by Bioshok7 · Sep 13, 2017 at 10:21 AM

Hello GenericToast,

thank you infinitely, you almost understood the question (I have wrongly expressed the problem),

I will give you an example to better understand the problem:

the platform translates to the right during its translation it can be blocked by any solid object including the player according to the level design,   in this case either it does not translate anymore from the blocking before it retranslate after a certain time in any of the other 3 senses where the platform is not yet blocked, or it translates directly without waiting in the 'one of the 3 remaining directions or sens where it is not yet blocked,

the blocking of the platform can be done in one direction (here only on the right) or in a maximum of two directions (eg right and up) and can in this case retranslater in the remaining directions where it is still free and not blocked,   another thing is it a good idea to implement this function in the oncollisionenter2d platforms ? is it better in general to add rigidbody2d for any gameobject other than player ? and without rigidbody2d collision not detected between 2 gameobjets in this case that do not include the player,

please if you do not mind giving me the full source code of the ideal solution to better understand it,

Thank you for your understanding.

Comment
Add comment · Show 1 · 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 Bioshok7 · Sep 14, 2017 at 09:56 AM 0
Share

up please thank you

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

69 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

Related Questions

Making a smooth camera translation and rotation, C# 1 Answer

Move Objects Relative in Viewport 2 Answers

Language/translation connector to Unity - will it be useful? 0 Answers

Is "Block color" possible in unity? 2 Answers

How do I translate my ship left and right and have it rotate at the same time? 1 Answer


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