Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 bummer6 · Mar 23, 2013 at 10:19 PM · triggerobjectmovemoving

How do I move an object from point A to point B using a trigger?

I'm basically trying to move a box from one side of the room to the other when the player enters a trigger. It seems like such a simple task, but all the solutions I've found seem extremely complicated... I'm a complete newbie to coding in general, so I'm sorry if I'm a bit dumber than you guys are used to.

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 helloiam · Mar 24, 2013 at 11:01 AM

The trigger is easy that is what you have to find out for yourself

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 Kajos · Mar 24, 2013 at 09:14 AM

Perhaps something like this? Would differ if you would use physics.

 public Transform gotoPosition;
 private Transform oldPosition;
 private float percentage = 0.0f;
 public float speed = 0.1f;

 public bool collided = false;

 void Update() {
  if (collided && percentage < 100.0f) {
   if (percentage == 0) oldPosition = transform.position;
   float percentageIncrease = Time.deltaTime * speed;
   transform.position += (gotoPosition - oldPosition) * percentageIncrease;
   percentage += percentageIncrease; 
  }
 }

 // Second script for the trigger
     public GameObject player;
     public GameObject box;
     void OnTriggerEnter(Collider collider) {
      if (collider.gameObject == player) {
       AboveScriptName script = (AboveScriptName) box.getComponent("AboveScriptName");
       script.collided = true;
      }
     }
Comment
Add comment · Show 4 · 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 bummer6 · Mar 24, 2013 at 09:31 AM 0
Share

that looks somewhat simpler than the other solutions I've seen, but I don't understand how to tell the trigger that I want THE BOX to move, not the trigger itself. Also, where do I specify the old and goto positions? Right now they don't appear to have a value...

avatar image Kajos · Mar 24, 2013 at 09:46 AM 0
Share

Apply the trigger to a gameobject other than the box (and not the box as parent). Apply the script to the box, and set the gotoPosition to a (possibly empty deactivated) gameobject where you want the box to go to. $$anonymous$$ake sure there are rigidbodies attached (not necessary for the box).

avatar image Kajos · Mar 24, 2013 at 09:52 AM 0
Share

This is code I wrote from the top of my head, so it might contain some errors in syntax.

avatar image helloiam · Mar 24, 2013 at 10:50 AM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html http://docs.unity3d.com/Documentation/ScriptReference/Vector3.$$anonymous$$oveTowards.html

These two is if you want to have that a object goes from point A to B.

avatar image
0

Answer by helloiam · Mar 24, 2013 at 11:01 AM

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

Take a loot at this, maybe this will answer your question, you can also use MoveTowards

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.MoveTowards.html

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

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 make a moving object 2 Answers

Moving an Object towards another Moving Object 2 Answers

How Can I Make a Moving Object with a trigger reaction ? [C#] 1 Answer

How can i do so when my car moves an object follows it? 1 Answer

Moving an object 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