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 Tanapat · Jan 12, 2013 at 10:56 AM · transform

I need help ! = Tranform.position ?

I want the items moved to the second position x,y (red line)

but But only one is available.

Javascript Code:

function OnCollisionEnter (collision:Collision)

{

if(collision.gameObject.tag =="player")

{

transform.position.x = Random.Range (-30,33);

transform.position.y = -10.6062;

transform.position.x = Random.Range (-66,-52);

transform.position.y = -9.050232;

}

}

alt text

cats00.jpg (121.4 kB)
Comment
Add comment · Show 4
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 PushpaK · Jan 12, 2013 at 11:14 AM 0
Share

Try this one.I havent tried it function OnCollisionEnter (collision:Collision)

{

if(collision.gameObject.tag =="player")

{ if(transform.position.y==-9.050232) { transform.position.x = Random.Range (-30,33); transform.position.y = -10.6062; } else if(transform.position.y==-10.6062) { transform.position.x = Random.Range (-66,-52); transform.position.y = -9.050232;

}

}

avatar image $$anonymous$$ · Jan 12, 2013 at 11:34 AM 0
Share

Not sure what this is about.. but I know that checking for floating point equality like this is not a good idea. Also please format the code you paste here!

avatar image Tanapat · Jan 12, 2013 at 12:21 PM 0
Share

i try but no item no transform T.T

function OnCollisionEnter (collision:Collision)

{

if(collision.gameObject.tag =="player")

{ if(transform.position.y==-9.050232) { transform.position.x = Random.Range (-30,33); transform.position.y = -10.6062; } else if(transform.position.y==-10.6062) { transform.position.x = Random.Range (-66,-52); transform.position.y = -9.050232;

}

}

avatar image $$anonymous$$ · Jan 12, 2013 at 12:28 PM 0
Share

never $$anonymous$$d

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jan 12, 2013 at 12:44 PM

I'm not sure what exactly you want to do. I guess you want the item, when it is touched by the player and somewhere in the first area to move to the second atea and reverse.

Your code sets both position so only the last assignment will be used. You have to check where the item is at the moment of the collision.

Something like this:

 // UnityScript
 function OnCollisionEnter (collision:Collision)
 {
     if(collision.gameObject.tag =="player")
     {
         if (transform.position.y > -10)
         {
             transform.position.x = Random.Range (-30,33);
             transform.position.y = -10.6062;
         }
         else
         {
             transform.position.x = Random.Range (-66,-52);
             transform.position.y = -9.050232;
         }
     }
 }

Since we don't know more about the mechanics in your game i can't give a more detailed / optimised answer.

Comment
Add comment · Show 8 · 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 Tanapat · Jan 12, 2013 at 03:33 PM 0
Share

i want item transform is in red line (random)

alt text

avatar image Wolfram · Jan 12, 2013 at 03:36 PM 0
Share

There are two red lines in your picture, it is still unclear what you want, please explain with more words.

avatar image Tanapat · Jan 12, 2013 at 03:43 PM 0
Share

if player pick item , item random position As required.

alt text

Thank You all

avatar image $$anonymous$$ · Jan 12, 2013 at 03:47 PM 1
Share

oh come on... "as required"? What's the requirement?

avatar image Wolfram · Jan 12, 2013 at 03:52 PM 1
Share

Please use Google translate if you're having trouble finding the best English words.

Show more comments

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

12 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

Related Questions

How to reset a gameobject's transform? 2 Answers

Offset transform.parent.position - Help 1 Answer

measuring proximity with transform.distance 2 Answers

Move an object toward an angle in 2d space 0 Answers

make player move in direction it's facing 2 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