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 Abdou23 · May 12, 2014 at 05:15 AM · movementiphone2d-gameplay

Move sprite from point A to point B

Hi, Pretty new to Unity and i'm trying to make a very simple iphone game. , I'd like to know how to move a sprite (2D) move from random point A to random Point B not just that, but i want it to change direction halfway through.

Thank You.

Comment
Add comment · Show 9
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 robertbu · May 12, 2014 at 05:20 AM 0
Share

Your question is both fuzzing and has been covered many times. It is also covered in many basic tutorials. Please search out and try the many answers on now to move objects from one position to another. If you get stuck, posts back with your attempt.

The rotation is a separate issue. We try and keep Unity questions to a single issue. If you end up asking the rotation as its own question at some point, be specific. What two directions will the object be looking at? Does the rotation change over time? If it changes over time, is it a continuous change from the start to end movement, or a quicker rotation in the middle of the movement? Etc.

avatar image Abdou23 · May 12, 2014 at 06:16 AM 0
Share

I already used google and youtube before asking here, some people used AddForce others used whole bunch of If statements. I really want something simple. As for the rotation, it's a 2d game so we only use (x,y) and i want it to happen only 1 time.

You could at least pinpoint me to a respectful tutorial or something. Someone else might have if it stayed opened.

avatar image robertbu · May 12, 2014 at 06:39 AM 0
Share

You question comes across as a write-it-for-me question. You describe the specification for what you want but don't show that you've done any work on the problem. And you don't provide critical information for someone to give you an accurate answer.

  • $$anonymous$$ovement by Transform

  • $$anonymous$$ovement by Ridbody

  • $$anonymous$$ovement by CharacterController

  • Does the movement need support collisions

  • Nature of the rotation

  • Etc.

I just did a Google search for "unity3d move object between two points," and found half a dozen useful web pages on the first page of results (including the reference page for Vector3.Lerp()). If you'd come to the table with any sort of attempt to solve the problem on your own, I would have left it open.

avatar image Abdou23 · May 12, 2014 at 07:37 AM 0
Share

here is my attempt:

 public float speed;
 public float $$anonymous$$Force; 
 public float maxForce;
 public float counter;
 private float counter2;

 void Start () 
 {
 Push ();

 }

 void Update ()
 {
 counter2 -= Time.deltaTime;
 if ( counter2 < 0)
 {
     Push ();
     counter2 = counter;

 }

 }


 void Push ()
 {
 float force = Random.Range($$anonymous$$Force, maxForce);
 float x = Random.Range(-1f, 1f);
 float y = Random.Range(-1f, 1f);

 rigidbody2D.AddForce( force * new Vector2(x, y) * speed);
 }

 }


I'm not quit satisfied with using force, also tried Vector2.lerp but for some reason it just teleported ins$$anonymous$$d of smoothing. Also i want to make it randomly change position only once.

here is my Lerp attempt:

     private Vector2 startPoint ;
 
 
 public float speed ;
 public float counter;
 private float counter2;
 
 void Start () 
 {
     startPoint = transform.position;
 }
 
 // Update is called once per frame
 void Update () 
 {
     counter2 -= Time.deltaTime;
     if ( counter2 < 0)
     {
         RandomPosition ();
         counter2 = counter;
 
     }
 
 }
 
 void RandomPosition ()
 {
     float counter = speed * Time.deltaTime;
     float x = Random.Range(-50f, 50f);
     float y = Random.Range(-100f, 100f);
     Vector2 endPoint = new Vector2(x, y);
     transform.position = Vector2.Lerp(transform.position, endPoint,       Time.deltaTime * speed);  
 }
 }
avatar image robertbu · May 12, 2014 at 08:04 AM 0
Share

With the addition of code, I reopend the question.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Replacing iTween.MoveUpdate with iTween.MoveTo 1 Answer

how do I sync movement with mouselook 1 Answer

Angry Birds hold, drag and catapult an object ... 2 Answers

iPhone Touch RayCastHit problem 2 Answers

Gyroscope based First person controller 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