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 Caiuse · Feb 24, 2011 at 07:09 PM · transformpositionsmoothbce0020

Smooth Moving GameObject

I can't seem to apply a Vector.Lerp because the var buildingObject is a GameObject and not Transform. how can I convert it into a Transform purely for the purpose of making it smooth move, without actually changing the var type.

var buildingObject : GameObject; var myGround : Transform; var smooth = 5.0;

 function Update () {
         checkForBuilding();
 }

 function checkForBuilding() {
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hit : RaycastHit;
          if (Physics.Raycast (ray, hit, 100.00) && hit.collider.gameObject.CompareTag("CursorSnap")){
                 buildingObject.transform.position = hit.point;  
         }

 }

Using

buildingObject.transform.position = Vector3.Lerp (hit.point, Transform.position,Time.deltaTime * smooth); 

returns the error BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'. maybe i've interpreted it wrong.

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
2
Best Answer

Answer by Alec-Slayden · Feb 24, 2011 at 07:21 PM

It shouldn't matter that the variable is a game object, since game objects inherently have transforms. Just make sure what you're using the Vector3.Lerp on is buildingObject.transform.position or .rotation

Make sure in your lerp that you use

transform.position

NOT

Transform.position

Transform with a capital 'T' is a type, like integer or float. The compiler wants to know what transform to use.

transform with a lowercase 't' refers to whatever transform this script is attached to.

In addition, it looks like you're trying to move the building smoothly to the hit.point. if thats the case, you may want to use this instead:

buildingObject.transform.position = Vector3.Lerp(buildingObject.transform.position, hit.point,Time.deltaTime * smooth); 

Lerp has the parameters (from, to, speed/time), so you'll want to use its position, not the script transform's position (assuming you're not running this script from that building object).

The effect this has will be a decelerating Lerp. If you want a smooth A to B without slowing down much, consider SmoothDamp instead :)

Comment
Add comment · Show 6 · 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 Caiuse · Feb 24, 2011 at 07:27 PM 0
Share

using 'buildingObject.transform.position = Vector3.Lerp (hit.point, Transform.position,Time.deltaTime * smooth);' returns the error 'BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'.' maybe i've interpreted it wrong.

avatar image Alec-Slayden · Feb 24, 2011 at 08:46 PM 0
Share

I expanded a little bit, I think I have a better picture of what you're trying to do, hopefully this clears things up :)

avatar image Caiuse · Feb 24, 2011 at 09:07 PM 0
Share

Thats perfect, that was so frustrating how close i was :/ thanks, but after all of that that didn't solve my problem of "jerky" movements :(

avatar image Alec-Slayden · Feb 24, 2011 at 09:17 PM 0
Share

aw =( what kind of jerky movements are happening?

avatar image Caiuse · Feb 24, 2011 at 10:24 PM 0
Share

http://answers.unity3d.com/questions/43204/jumpy-movements-with-transform-position/43215#43215

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

1 Person is following this question.

avatar image

Related Questions

How Can I Make The Parkour Moves Move Smoothly Instead Of Instantly Teleport? 1 Answer

How to smooth movement object in one-axis? 1 Answer

Transform.position can't be changed smoothly. 2 Answers

make player move in direction it's facing 2 Answers

What is the reasoning of multiplying by Time.deltaTime 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