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 MC HALO · May 07, 2011 at 03:03 AM · positionaxis

How to stop at a point of axis?

Hi all, was wondering if some one could help me. basically i have a object and its Y axis is 8.049514 at the moment. now this object goes up and down. the down bit works perfectly. but when it starts to go back up it keeps on going. basically what i need is to find out if the gameObject has passed the Y axis position that it is set to which is 8.049514. now if this is true i just want to activate my boolean called hitfloor i want to set this to false. i would be really happy if someone could help me :) thanks in advance MCHALO

SCRIPT:

var DownSpeed : float = 20; var BackUpSpeed : float = -0.1; var StopDownSpeed : float = 0;

var hitfloor : boolean = false; function Start () {

DropStone (); }

function Update (){

var hit: RaycastHit;

   Debug.DrawRay (transform.position,-Vector3.up * 5, Color.red);
   if(Physics.Raycast(transform.position , -Vector3.up , hit, 5)){

        if(hit.collider.gameObject.tag == "Ground"){


                 hitfloor = true;

                       //Debug.LogError("you have hit the floor");


        }
   }
   DropStone();
   }

function DropStone (){

if(hitfloor == false){ rigidbody.AddForce(-Vector3.up * DownSpeed ); } if(hitfloor == true) {

rigidbody.AddForce(Vector3.up * -BackUpSpeed );

}

if(gameObject.transform.up = 8.049514){ }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by DaveA · May 07, 2011 at 03:16 AM

if(gameObject.transform.up = 8.049514){

First, should be == not =

Second, it should be transform.y

Third, the odds that, if it's moving, that it will be exactly this value are very small. Better to test around a range

if (gameObject.transform.y >= 8.04 && gameObject.transform.y <= 8.05)

but this will depend on the speed. Perhaps you want to detect when it passes this value in one direction or another:

if (gameObject.transform.y >= 8.04)
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 MC HALO · May 07, 2011 at 03:16 AM 0
Share

thank you very much master yoda lol

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

No one has followed this question yet.

Related Questions

How to Lerp a position along one axis only? 2 Answers

camera transform not working when getting axis position 3 Answers

How do I make one transform rotation the same as anothers? 2 Answers

Vector 3 - move on only one axis 0 Answers

Hinge joint target angle and joint axis 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