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 /
This question was closed Dec 22, 2013 at 11:58 AM by Inan-Evin for the following reason:

Other

avatar image
0
Question by Inan-Evin · Dec 22, 2013 at 11:13 AM · objectvector3directionmove

Make a moving object continue it's movement from the same direction , even it reaches target

Hello everyone, I'm stuck at a point in my game. I have a top-down camera, and a cube as a player. Cube fires projectiles by mouse click, we fire projectile to the position of mouse input, i achieved this with click to move code in unity wiki, basically we have our position defined as targetPosition in Attack.js .

Now in my projectile script, I did this :

 private var positionToGo : Vector3;
 function Start () {
 
 positionToGo = Attack.targetPosition; // our var positionToGo equals to mouse input pos now
 
 }

Now when I fire my projectile, it goes to the mouse input, that's cool. But it stays there, i want to make it continue it's way in the same direction but whatever i tried it always changes direction, I couldn't find any solution since I use this to move projectile to mouse position:

 transform.position = Vector3.MoveTowards(transform.position, positionToGo, Time.deltaTime * projectileSpeed);

So I tried doing something like this :

     if(Vector3.Distance(transform.position,positionToGo)>10 && canMoveToMouseClick)
         {
          transform.position = Vector3.MoveTowards(transform.position, positionToGo,  Time.deltaTime * projectileSpeed);  
 // if projectile is still far away from mouse position, make it go to the mouse position
         }
        if(Vector3.Distance(transform.position,positionToGo)<10)
         {
          canMoveToMouseClick = false; // if it's close enough to mouse position, make a variable false
         }
        if(!canMoveToMouseClick)
         {
           // and if that variable is false, make the game object move without changing it's direction, but how ?
     // you know something like 
     // transform.Translate(transform.forward * Time.deltaTime * projectileSpeed, Space.Self);
     // but it doesnt work, it just changes direction both i tried self and world.
     
         }

So can anyone help guys ? 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

  • Sort: 
avatar image
0
Best Answer

Answer by Inan-Evin · Dec 22, 2013 at 11:57 AM

 Okay I solved it, 
 transform.Translate(directionObject.transform.forward * Time.deltaTime * projectileSpeed, Space.Self); // directionObject whose transform looks at mouse input position. I'm not deleting post maybe someone will have similar problem.
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

18 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

Related Questions

Units merge into each other with pathfinding 1 Answer

Local FPS Gravity Changing Lerp 0 Answers

How to know from which direction there is a collision with an object? in C# 1 Answer

How to change use transform.LookAt to make the bottom of an object look at something? 0 Answers

Move the player towards the cube to attack. 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