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 Mirez · Oct 01, 2012 at 01:20 PM · objectvector3movingtransparent

Moving an object

I'm trying to write a small code to smootly move a cube from it's starting position to it's target position. I found a code on this website but I'm not sure how to use it.

 var start : Transform;
 var end : Transform;
 
 function Update ()
 {
     transform.position = Vector3.Lerp(start.position, end.position, Time.time); 
 }
 

This makes the object go to 0,0,0 in a matter of seconds, how do I specify the end position?

Also I would like if the object would be transparent before and after moving.

Comment
Add comment · Show 9
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 shaderop · Oct 01, 2012 at 01:25 PM 1
Share

It would probably be a good idea to read a tutorial on scripting and Unity. The Walker Boys tutorials are a good start (http://www.walkerboystudio.com/html/unity_training___free__.html)

avatar image Mirez · Oct 01, 2012 at 02:23 PM 0
Share

That's not useful at all, I can't be bothered watching long winded tutorials about printing in the hope I find something useful. I tried using a code they used and it gave a ton of errors, I think it's dated.

Right now I found something in the script reference:

var start : Transform; var end : Transform; function Update () { transform.position = Vector3.Lerp(start.position, end.position, Time.time); }

but it gives me the error "The variable start of 'Ghost' has not been assigned." which essentially gives me the same problem.

How do I specify the target?

avatar image FatWednesday · Oct 01, 2012 at 02:23 PM 2
Share

In future please format code in posts using the "0100101" button in the post editor.

Also you might have better luck using function Update() ins$$anonymous$$d of the OnTriggerExit function.

avatar image AlucardJay · Oct 01, 2012 at 02:55 PM 0
Share

It is only going to get harder trying to splice snippets of code together if you don't have a basic understanding of what is happening.

If the target is a Vector3 and not a Transform, then :

 transform.position = Vector3.Lerp (transform.position, target, Time.deltaTime * 5.0);

Of course this won't mean anything to you without understanding a Transform and a Vector3.

Here is the Unity Scripting Reference : http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

These video's are not long-winded, very short, concise and full of useful information :

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/

avatar image Mirez · Oct 01, 2012 at 03:26 PM 0
Share

I do understand a vector3 and a transformation. But how do I specify the target?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ZenithCode · Oct 02, 2012 at 01:05 PM

Try this.

  1. Go on your scene

  2. Create an empty game object and place it at the end position

  3. GO on your script where you are doing the LERP and type this code.

    public Transform target;

    transform.position = Vector3.Lerp(start.position, target.position, Time.time);

  4. In the Unity editor, drag the 'target' game object onto the public field target.

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

13 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

Related Questions

how to make a moving object 2 Answers

Moving an object in 3D Space ~ Complexity 1 Answer

Rotate Sphere in the same place in Android touch 1 Answer

overlapping object doesn't disable 1 Answer

How to moving objects up and down slowly? 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