Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 player2 · Jul 01, 2012 at 04:55 PM · collidertriggerboolean

constricting movement to cubes via collider-trigger-boolean scripting confusion

i'm trying to set up a script that will turn booleans on or off depending on triggers, in this example i'd like the red block to only be able to move to the edge of the green cubes and no further.

here's where i' m mostly failing at the moment: if i add an OnTriggerExit function to turn the boolean off it'll not be on even if the space it moves to is of the same type (i suppose because it's calling Exit on that trigger, which is fair enough), i've tried a few things and lots of head-scratching.

alt text i've set up 4 colliders surrounding the player piece (which only moves 4 directions) and set them to trigger (or more like tried to) whenever they collide with various tagged objects in hope that it'd be straight forward to set up the movement script to ask if the boolean is on/off to allow movement in that direction (if north collider is colliding with floor, for example, movement north is possible).

here's one of the many mashed-up scripts i now have:

 script
 var target: Transform; // tagged "Block"
 
 // var stone: Transform; // tagged "Block"
 
 // var water: Transform; 
 
 var onfloor: boolean = false;
 var inSpace: boolean = false;
 
 /*function Start(){
     if (target == null && GameObject.FindWithTag("Block"))
     target = GameObject.FindWithTag("northTrigger").transform;
 }*/
 
 function OnTriggerEnter() {
 
      if(target.gameObject.tag == "Block"){
      onfloor = false;
      collider.isTrigger = true;
      print("north is grass");
      collider.isTrigger = false;          
      }
      
      if(target.gameObject.tag != "Block"){
      onfloor = false;
      collider.isTrigger = true;
      print("north is grass");
      collider.isTrigger = false;          
      }
 }
 
 
 /*
 function OnTriggerExit() {
      if(target.gameObject.tag == "Block"){
 //     collider.isTrigger = true;
   ongrass = true;
      print("north is nothing");
 //     collider.isTrigger = false;          
      }
 }
 */


sory about the formatting there, can't even work out how to get that to print straight here, the "/" are supposed to be commented out sections incase you'd not gathered by now:/. as you may notice if you've bothered to read this far, i'm almost absolutely useless at this stuff:( no doubt there are myriad better and simpler solutions to this problem, i would like to hear of those that don't include rigidbodies too if you're prepared to write them... thanks also does anyone of a simple line-of-sight checking script i can rip that works[like this but maybe better:?

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 whydoidoit · Jul 01, 2012 at 04:54 PM 0
Share

Format your code by indenting 4 spaces or 1 tab before pasting, or highlighting it and clicking the code button after pasting. Will fix it for you this time.

avatar image player2 · Jul 02, 2012 at 07:02 PM 0
Share

thanks, something useful i forgot to mention would be that the player piece here moves without deltaTime, probably more info would help to help:/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by player2 · Jul 03, 2012 at 08:12 AM

so... incase anyone's interested i've created a most inelegant piece of script and eight colliders (two for each direction)to deal with this but now need to write them in somehow... in this example the collider scripts are called triggerNorthDown and triggerNorthUp, the booleans they switch are called NDownSafe and NUpSafe respectively and should both read safe to allow movement;) here's how i've butchered the movement script so far:

 var roll:int=5;
 var extpace:int=0;
 var movespeed : int = 12;
 
 function Start ()
 {}
 
 function Update () 
 
 {
 if (
  gameObject.GetComponent(triggerNorthDown)NDownSafe == true && 
  gameObject.GetComponent(triggerNorthUp)NUpSafe == true &&
  roll+extpace>=0 
  && Input.GetButtonDown("forward"))
  {
  transform.position.z += 1.0;
  }
  if (extpace+roll>=0 && Input.GetButtonDown("backward"))
  {
  transform.position.z += -1.0;
  }
  if (extpace+roll>=0 && Input.GetButtonDown("left"))
  {
  transform.position.x += -1.0;
  }
  if (extpace+roll>=0 && Input.GetButtonDown("right"))
  {
  transform.position.x += 1.0;
  }
 }

i'm sure it must be something like this:/...

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble getting a trigger to activate an animation 2 Answers

Check if trigger collider is touching other trigger collider 2 Answers

Can't click gameobject when over another trigger? 1 Answer

Using a trigger collider to detect enemies. 1 Answer

Have something be a trigger and a collider? 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