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 TomHartO · Dec 10, 2012 at 04:03 PM · positionobjectmove

Move one object to anothers position over time.

I'm trying to move my FPS object to a new location quickly, roughly 2-3 times its running speed.

I currently have this to move his position

Player.transform.position.y = hit.transform.position.y+5; Player.transform.position.x = hit.transform.position.x; Player.transform.position.z = hit.transform.position.z;

However that obviously moves him instantly. How would I get him to move at the desired speed?

Comment
Add comment · Show 5
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 TomHartO · Dec 11, 2012 at 09:01 AM 0
Share

I tried using Lerp but it still jumps him there instantly.

Here's how I added it into my code, should I split the other stuff outta the update function and leave just the lerp in?

 function Update () {
     var hit: RaycastHit;
     if(Physics.Raycast(Gun.transform.position, Gun.transform.forward, hit)){
         if(hit.transform.tag == 'JumpTo'){
             Text.guiTexture.enabled = true;
            
             if(Input.GetButtonDown("Fire1")){
                 var distance = Vector3.Distance(Player.transform.position,hit.transform.position);
                    
                 if(distance < 17)
                     Player.transform.position =  Vector3.Lerp(Player.transform.position, hit.transform.position+(Vector3.up*5), Time.time);
             }
         }
         else
             Text.guiTexture.enabled = false;
     }
 }
avatar image whydoidoit · Dec 11, 2012 at 09:55 AM 0
Share

Don't use Lerp with Time.time - that just moves it to the end position if the game has been running for more than 1 second. See this article on Unity Gems

avatar image TomHartO · Dec 11, 2012 at 10:52 AM 0
Share

Thanks for the link, I can see that being very useful for me :p. However using those in my script only moves the character whilst the mouse is pressed down, i guess cause its inside the if(Input clause.

How would I stop this? Could I make a new function and pass the positions in?

avatar image whydoidoit · Dec 11, 2012 at 10:55 AM 0
Share

You could make a targetPosition when the button is down and then do the Lerp to the target position outside of the raycast if - so perhaps at the bottom of your Update function.

avatar image TomHartO · Dec 11, 2012 at 11:08 AM 0
Share

Okay I think I should be able to get that sorted. Only other problem I'm having is using Lepr my character slides along the ground, I need him to also move up too as 90% of the targets will be above him.

$$anonymous$$oving my guy to hit.point+(Vector3.up*5); moves him to exaclty where I want him, but using that in the Lerp he just slides.

Any idea why or how I could stop this?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Dec 10, 2012 at 04:09 PM

for an FPS you should probably be using a charactercontroller for the player and then you can use

Player.charactercontroller.simplemove(speed * direction)

you can use slerp to move that transform but even moving slowly moving a transform directly TELEPORTS the object. It makes no attempt to check for collision and will go straight through any object in the game.

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 Jake.OConnor · Dec 10, 2012 at 07:12 PM

You can use the Vector3.Lerp() function to lerp between the starting and target position over a given period of time, or if you need more specific controls you can use the Lerp function in Mathf. (You'll need to use the Lerp in one of your update functions to smooth out the movement over a number of frames.)

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

changing pivot's placement 2 Answers

How to move an object from one position to desired position? 0 Answers

Script to move an objects position and rotation upon collision with player? 1 Answer

2D get touch input 1 Answer

how to set rotation / position of an object on trigger? 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