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 RaulG · Jul 31, 2013 at 01:20 AM · vector3.lerpmovinggameobjectvector3.movetowards

Object snaps from point A to B

I'm trying to move my object from point A to B without it snapping.

I have used:

Vector3.MoveToward

and

Vector3.Lerp

Maybe I am not using it right?

I also tried a While loop

 while (HookShot == true)
         {
             if (HookShot == false)
             {
                 break;
             }
             HookChild.Translate(Vector3.MoveTowards(Player.transform.position,HookHit.point,Mathf.Infinity));
         }

Which basically caused a crash.

  void Update () 
     {      
         if (GameObject.FindGameObjectsWithTag("Hook").Length != 1)
         {
             HookChild = Instantiate(Hook,new Vector3(Player.position.x,Player.position.y,Player.position.z + 2) 
                         ,Quaternion.identity) as Transform;
             HookChild.transform.parent = Player;
             HookShot = false;
         }
         if(GameObject.FindGameObjectsWithTag("Rope").Length != 1)
         {
             RopeChild = Instantiate(Rope,new Vector3(HookChild.position.x, HookChild.position.y,HookChild.position.z)
                         ,Quaternion.identity) as Transform;
             RopeChild.transform.parent = Player;
             RopeChild.localScale = new Vector3 (0.5f,2.0f,0.5f);
         }
        //-----------------------------------------------------------------------------------//
        Ray HookRay = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
        Debug.DrawRay(HookRay.origin,HookRay.direction,Color.green);
        Vector3 curHookPos = HookChild.position;
        Vector3 newHookPos = HookChild.position;
  
        if (Input.GetMouseButtonDown(0))
        {
          if(Physics.Raycast(HookRay, out HookHit, 50.0f) == true)
          {
              HookShot = true;
               Debug.DrawRay(HookRay.origin,HookRay.direction, Color.red);
                Debug.Log("Hook was hit");
              newHookPos = Vector3.Lerp(curHookPos,HookHit.point,speed * Time.deltaTime);
              RopeChild.localRotation = Quaternion.LookRotation(Player.transform.forward,HookHit.point);
              RopeChild.localScale += ropeMoveTowards * Time.deltaTime;
          }
        }
          else if (Input.GetMouseButtonUp(0))
        {
          newHookPos = curHookPos;
          RopeChild.rotation = Quaternion.identity;
          RopeChild.localScale = new Vector3 (0.5f,2.0f,0.5f);
          HookShot = false;
        }
     }



Ignore the Rope stuff, I'm just messing around with that.

Comment
Add comment · Show 1
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 nixcs2512 · Jul 31, 2013 at 04:41 AM 0
Share

I don't know why $$anonymous$$oveToward is wrong? Just simple:

 public float moveSpeed; //the speed of object you wanna move
 void Update()
 {
 transform.position =Vector3.$$anonymous$$oveToward(transform.position,target.transform.position,moveSpeed*Time.deltaTime);
 }

Target is a GameObject type.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RPGstandard · Jul 31, 2013 at 01:26 AM

Is this what your looking for?

http://docs.unity3d.com/Documentation/ScriptReference/Handles.FreeMoveHandle.html

Comment
Add comment · Show 9 · 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 RaulG · Jul 31, 2013 at 01:33 AM 0
Share

Can you convert that to C#? It won't change it on the Docs.

avatar image RPGstandard · Jul 31, 2013 at 01:48 AM 0
Share

Typically if it doesnt change inside the Docs than it should work in either language.

avatar image RaulG · Jul 31, 2013 at 04:29 AM 0
Share

I don't know if you could use Javascript stuff in C#...

avatar image RPGstandard · Jul 31, 2013 at 04:36 AM 0
Share

none of the code in the linked Doc is Javascript or C# specific.

avatar image RaulG · Jul 31, 2013 at 04:41 AM 0
Share
     // Create a simple move handle (Twice as big) on the 
     // target object that lets you freely move the Object
     // Without having the "$$anonymous$$ove" button selected
     
     @CustomEditor (Free$$anonymous$$ove)
     class Free$$anonymous$$oveHandleJS extends Editor {
         function OnSceneGUI () {
             target.pos = Handles.Free$$anonymous$$oveHandle(target.pos, 
                             Quaternion.identity,
                             2.0,
                             Vector3.zero, 
                             Handles.DrawRectangle);
             if (GUI.changed)
                 EditorUtility.SetDirty (target);
         }
     }
 
 
 
 @script ExecuteInEdit$$anonymous$$ode()
     
     var pos : Vector3 = Vector3(0,0,0);
     
     function Update () {
         transform.position = pos;
     }


That is Javascript right?

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

17 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 avatar image avatar image avatar image avatar image

Related Questions

moving an object from point to point using force 1 Answer

Does the speed of the object depends on target distance while using vector3.movetowards() 0 Answers

How do I move a Cube transform from one position to another smoothly? 1 Answer

MoveTowards won't translate on the y axis and lerp leaves character jittering in mid-air 0 Answers

Moving an object constantly between two points with a time delay inbetween 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