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 Abdulraahman · Jul 11, 2017 at 01:32 PM · colliderplayerontriggerenter

How to make player go through object but can't go back

Hi, I'm making a magic wall which allow player to go through but can't go back. How to do this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JimmyVegas · Jul 11, 2017 at 01:41 PM

Pretty easy way would be to do this:

  1. Turn off the BoxCollider on the wall.

  2. Place a trigger on the other side of the wall which activates the BoxCollider when you step into it.

Example:

 public GameObject theWall;
 
 public void OnTriggerEnter () {
     theWall.GetComponent<BoxCollider>().enabled = true;
 }


Assuming there would be nothing going through the wall apart from the player, this should work. If you have other things, use a Tag.

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 Abdulraahman · Jul 11, 2017 at 04:55 PM 0
Share

sorry but it doesn't work I'm using Java so i tried to understand it and use it but i can't

avatar image
1

Answer by JustinEllis · Jul 11, 2017 at 06:19 PM

Well if its just linear movement you could put a box collider on the wal. Mark it as trigger, and then in your player script have this

 function OnTriggerExit(other: Collider)
  {     
 
      if(other.gameObject.tag == "WallTag")
      {
 
           other.IsTrigger = false;
 
      }
 
  }
 

Im not sure if that works or not but it makes sense to me. I usually on use C# so some of the syntax might me wrong. If your project is 2d use OnTriggerExit2. Remember you have to create a new tag a lnd put it in all the walls

Comment
Add comment · Show 7 · 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 Jwizard93 · Jul 11, 2017 at 08:34 PM 0
Share

Wouldn't this suddenly displace either either object? Or make the player immovable? I'm imagining what happens when a player collides with a collide instantiated right on them like a poorly configured weapon object.

avatar image Cornelis-de-Jager Jwizard93 · Jul 11, 2017 at 10:11 PM 0
Share

@jwizard93 No Since it is OnCollisionExit. $$anonymous$$eaning when this object gets its collider back it won't be colliding with the player.

avatar image Abdulraahman · Jul 12, 2017 at 12:52 AM 0
Share

sorry but it still doesn't work

avatar image Cornelis-de-Jager Abdulraahman · Jul 12, 2017 at 01:40 AM 0
Share

Is your object/wall set as a trigger?

avatar image Abdulraahman Cornelis-de-Jager · Jul 12, 2017 at 02:45 AM 0
Share

yes, it is

avatar image JustinEllis · Jul 12, 2017 at 02:36 AM 0
Share

Also make sure that youre player has a collider as well that is not marked as trigger. Try using debug statements in your collision to see if its even registering the collision.

it might also be other.collider.isTrigger

avatar image Abdulraahman JustinEllis · Jul 12, 2017 at 07:51 AM 0
Share

Still not working :(

avatar image
0

Answer by Cornelis-de-Jager · Jul 12, 2017 at 01:45 AM

On your wall object (Ensure the wall has a BoxCollider) add a new script and inside the script add the code below. :

 function Start () {
    GetComponent<BoxCollider> ().enabled = false;
 }
 
 function OnCollisionExit(other: Collision)
 {     
     if(other.gameObject.tag == "Player")
     {
           GetComponent<BoxCollider> ().enabled = true;
      } 
 }
 

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 Abdulraahman · Jul 12, 2017 at 07:46 AM 0
Share

Thank you for replying, But i have many errors.

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

89 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

Related Questions

specifying collider OnTriggerEnter 1 Answer

Player falling too fast for a collider to stop it 5 Answers

Only 1 of 3 conditions being executed in IF statement?(Solved) 1 Answer

OnTriggerEnter - Hit Only One Collider 2 Answers

Trigger and Collider Issues 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