Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Nov 25, 2015 at 07:25 AM by Le-Pampelmuse for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by pravinbudharap · Nov 23, 2015 at 12:58 PM · lerp

what wrong with lerp.

 using UnityEngine;
 using System.Collections;
 
 public class Mousedrag : MonoBehaviour {
     
 
     // Use this for initialization
 
     public Transform player;
     public float speed;
     void Start () {
 
     }
     // Update is called once per frame
     void Update () {
     if (Input.GetMouseButtonDown (0)) 
         {
             Debug.Log(Input.mousePosition);
             Vector3 newPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             float yPos = newPos.y;
             player.position=new Vector3(player.position.x,yPos,player.position.z);
 
                 player.position = Vector3.Lerp(player.position, yPos, speed);
 
 
         }
     }
 }

Comment
Add comment · Show 8
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 amanpu · Nov 23, 2015 at 01:01 PM 0
Share

What is value of speed ?

avatar image savlon · Nov 23, 2015 at 01:01 PM 2
Share

You aren't incrementing the speed variable. Well not that I can see anyway. It also appears you are using Lerp incorrectly. Look at this website, which will guide you in the right direction. http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly

avatar image Bonfire-Boy savlon · Nov 23, 2015 at 01:50 PM 0
Share

They don't necessarily need to change the speed variable.

avatar image savlon Bonfire-Boy · Nov 23, 2015 at 01:57 PM 0
Share

That is true, however, it's not the correct way to do it. It will constantly be lerping the position at whatever the value of "speed" is. When really, it should be a value that lerps between 0 and 1. 0% of the distance to 100% of the distance.

Show more comments
avatar image Bonfire-Boy · Nov 23, 2015 at 01:15 PM 3
Share

Does this code compile? You're passing a float as the second parameter to Vector3.Lerp, when it should be a Vector3. Looks to me like it should be newPos ins$$anonymous$$d of` yPos`. That would make player's position move towards newPos ie move towards the mouse pointer, on the x/z axes (you've already snapped its position to the same as newPos on the y axis).

I'm already guessing, though, since you tell us neither what the code's supposed to do nor what's going wrong.

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Le-Pampelmuse · Nov 23, 2015 at 02:54 PM

Hi. You have to be specific when asking a question on this forum.
Don't just post your script and ask people to correct it.
This is not how Unity Answers works.

Please read the Frequently Asked Questions and the User Guide.
This will help you to ask good questions later. :)

Your code has some errors that prevent Unity from even starting the scene: Vector3.Lerp() takes (Vector3, Vector3, float) and not (Vector3, float, float).
You declared yPos as a float.

If you look at the error in Unity, it will tell you that. :)

Have a nice day.

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

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Interpolated movement in a circle 1 Answer

Setting slider value over time using C# script? 0 Answers

Using lerp properly 2 Answers

Mathf.Lerp crashing build? 1 Answer

Vector3.lerp for moving transform 0 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