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 SlyyGuyy · Apr 05, 2014 at 05:08 PM · javascriptenemyenemyaienemy spawn

Moving character from point to point

Hey Unity Heroes,

I've been searching and searching for a way to move a character from point to point, but I can't seem to figure out how to actually get it done. I've seen it done by Lerping and moving back and forth between a position, but I just can't seem to be able to move an object from its starting position downward and then stay at that other position. Basically, what I have is a boss character that spawns at the top of the "playing field," which is off screen (my game is 2D btw) and then the boss is supposed to move downward slowly to a point and stay there so that the player can fight this boss. I'll post a screenshot of where the boss is spawning and then I'll post the code that I have for the boss movement. (EDIT) - The transform.position.x that you see is because I'm moving the boss back and forth on the X axis.

 #pragma strict
     
     //var target : GameObject;
     var pointA = Vector3(0, 15, 178);
     var pointB = Vector3(0, 0, 178);
     //private var startPosition : Vector3;
      
     function Start () {
         //transform.position = Vector3.Lerp(
         //transform.position = Vector3.Lerp(startPosition, target.transform.position, Time.deltaTime * 5);
     }
     
     function FixedUpdate () {
         transform.position.x = (Mathf.PingPong(Time.time * 3, 5) - 3);
         transform.position = Vector3(transform.position.x, transform.position.y, transform.position.z);
     }

![alt text][1] [1]: /storage/temp/24783-screen+shot+2014-04-05+at+12.03.24+pm.png

From the image you can see that the boss is spawned outside of the playing area. I want the boss to move downward slowly, to about where you can see the Pink and Blue objects, and then stop. Any help is greatly appreciated and if you need any further clarification, please do not hesitate to ask.

screen shot 2014-04-05 at 12.03.24 pm.png (42.0 kB)
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
1
Best Answer

Answer by sumeetkhobare · Apr 05, 2014 at 07:59 PM

 var hasFallenDown : boolean = false;
 var timeCount : float = 0;
 function Update()
 {
     if(!hasFallenDown)
     {
         transform.position = Vector3.Lerp(pointA,pointB,timeCount);
         timeCount += Time.deltaTime * 5;
         if(timeCount >= 1.0)
             hasFallenDown = true;
     }
 }

Try this code... mark as solve if it solves the problem.

Comment
Add comment · Show 1 · 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 SlyyGuyy · Apr 05, 2014 at 09:13 PM 1
Share

wow! thank you very much! This totally worked! $$anonymous$$uch appreciated! With some tweaking, I can get this fixed up more in no time.

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

Enemy ia fliping when hitting object 2 Answers

Problem with the movement of AI 1 Answer

How To Deactivate Enemy Shooting 1 Answer

Enemy not rotating when inside range 1 Answer

Enemy rotation issues - Javascript 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