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 Tyler 2 · Nov 24, 2010 at 05:35 AM · movementplatformermoving-platform

Move from point to point?

How would I make an object move from the position of object A, to the position of object B to the position of object C and then to A, etc. at a constant speed? I have tried looking into the "moving platform" script from the 2D platform tutorial from the unity resources but the speed seems to be based only on two objects, how can I have it be more (and at a constant speed)? Here is the script.

> var targetA : GameObject; var targetB
> : GameObject;
> 
> var speed : float = 0.1;
> 
> function FixedUpdate () {
>     transform.position =
> targetA.transform.position * speed
>                         + targetB.transform.position * speed; }

and here is a modified version (mine) that, when applied to an object, appears to do nothing(I am getting no errors though).

var targetA : GameObject; var targetB : GameObject;

var speed : float = 0.1;

function FixedUpdate () { transform.position = targetA.transform.position speed + targetB.transform.position speed; }

Thanks :)

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

Answer by BLF-Games · Nov 24, 2010 at 10:29 AM

I made this code and didn't test it, but it should work or at least close to solve your problem. It's in JavaScript.

//you can use Vector3 arrays instead of Transform and that way you avoid the need of GameObjects like this: /* var waypoint : Vector3[]; and you can set waypoints relative to object position and make different waypoints for any game object.. but that would need different coding :p */ var targetA : Transform; var targetB : Transform; var targetC : Transform;

private var currentTarget : Transform; var proximity : float = 1.0;

var speed : float = 1.0;

//with function Start we set at start the current target function Start () { currentTarget = targetA; }

function Update () { var Distance : Vector3 = currentTarget.transform.position - transform.position;

//if "player" is "1" unit far, change currentTarget to next one if(Distance.magnitude < proximity) { switch(currentTarget) { case targetA: currentTarget = targetB; break; case targetB: currentTarget = targetC; break; case targetC: currentTarget = targetA; break; } }

transform.position = Vector3.Slerp(transform.position, currentTarget.transform.position, Time.deltaTime * speed); //make object look towards currentTarget transform.LookAt(currentTarget); }

Now if you want to move your object through more complex waypoints i recommend you using arrays... I leave you this link from a code of mine but be aware it has some motion bugs...

http://answers.unity3d.com/questions/28390/enemy-jumping-with-each-waypoint-start

Comment
Add comment · Show 3 · 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 Tyler 2 · Nov 24, 2010 at 05:04 PM 0
Share

Thank you. I get an error when I am using the code

"Assets/NewBehaviourScript.js(43,38): BCE0017: The best overload for the method 'UnityEngine.Vector3.Slerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' is not compatible with the argument list '(UnityEngine.Vector3, UnityEngine.Transform, float)'."

avatar image BLF-Games · Nov 25, 2010 at 02:29 AM 0
Share

Ah yes, try changing in that line currentTarget to currentTarget.transform.position

avatar image Ninh · Mar 10, 2014 at 10:10 AM 0
Share

Is there any way to do somethings like this : gameObject.transform.$$anonymous$$oveTo(Point : transform,speed : float)

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

2 People are following this question.

avatar image avatar image

Related Questions

character controller sinks into platform while using raycast to detect collision 0 Answers

Moving platform and character controller 0 Answers

Creating a 2.5D Platformer.. use rigidbody/character controller, or custom code? 0 Answers

jittery collisions 2d platformer 1 Answer

Can't change direction mid-jump 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