Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by CatatonicFox · Jan 02, 2016 at 07:49 AM · c#movementtransformvector3turn-based

Turn Based Movement - Using Movement Points

Hi, I am Fairly New to Coding and Unity and I have been working on this Game for a little While and I have been Stumped with this Particular Problem.

I want to Limit my Gameobjects Movement by Movement Points, so It cant move more than its Movement points, I also want it so it can move Tiny bits inside the Movement Point Range.

Answers in C# Please.

Thanks in Advance for your Answers.

my Attempt At Making it Work

      public float MaxMovementPoints = 10f;
 float TravelCost;
 float MovementPoints;
 string Selected = "Not Selected";
 string Movement = "Not Moving";
 List<Vector3> waypoints = new List<Vector3> ();
 Vector3 mousePos;
 Vector3 MouseClick;
 Vector3 MouseClickFun;

 // Use this for initialization
 void Start ()
 {
     MovementPoints = MaxMovementPoints;
     print ("TravelDistance is in Start Replace ASAP, add it to Refresh or something Similar");
 }
 
 // Update is called once per frame
 void Update ()
 {

     //next turn refresh

     if (Selected == "Is Selected") {



         if (Input.GetMouseButtonUp (1) && Movement == "Not Moving") {

             //Creating the Vector 3 of the Mouse Click

             mousePos = Input.mousePosition;
             mousePos.z = Camera.main.transform.position.y;
             MouseClickFun = Camera.main.ScreenToWorldPoint (mousePos);

             MouseClick = new Vector3 (Mathf.Round (MouseClickFun.x), 0f, Mathf.Round (MouseClickFun.z));

             //Clearing the List if 'a new move Order' had been given Again
             if (waypoints.Count > 0) {
                 waypoints.Clear ();
             }

             //adding to the Position to Waypoints
             waypoints.Add (MouseClick);

             //Setting the Movement State to "Moving"
             Movement = "Moving";

             //Figuring the Travel cost by Distance and Clamping it so it doesnt Go over Max (And Create a Negative with MovementPoints or Under Zero
             TravelCost = Mathf.Clamp (Vector3.Distance (this.gameObject.transform.position, waypoints [0]), 0, MovementPoints);

             //Applies the Travel Cost to Movement Points
             MovementPoints -= TravelCost;

         }

         if (Movement == "Moving") {

             //This Moves the GameObject to the Waypoint 
             transform.position = Vector3.MoveTowards (this.transform.position, waypoints [0], 20*Time.deltaTime);


             //once Reached its Destination Its Ready to Recieve another Order
             if (this.transform.position == waypoints [0]) {
                 print("I Have Reached Mouse Click");
                 Movement = "Not Moving";
             }
         }
     }
 }

 void OnMouseUp ()
 {
     print (Selected);
     Selected = "Is Selected";
 }

Comment
Add comment · Show 3
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 g__l · Jan 02, 2016 at 12:56 PM 0
Share

would using Vector3.$$anonymous$$oveTowards help? http://docs.unity3d.com/ScriptReference/Vector3.$$anonymous$$oveTowards.html

avatar image CatatonicFox g__l · Jan 03, 2016 at 02:29 AM 0
Share

thank you for your answer, I am Going to use Vector3.$$anonymous$$oveTowards ins$$anonymous$$d of Lerp because i think it Works better for what I want. however my Problem is Constraining the movement with movement Points, I'll update the Question it make it more clear.

avatar image danielnetzer · Jan 12, 2016 at 12:07 PM 0
Share

you need a grid in order to use it the way you want, I'm working on something similar like Heroes of $$anonymous$$ight and $$anonymous$$agic world RTS game, and i'm using the mesh renderer with quads so each quad is a movement point.

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

57 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 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 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 GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer

Operator '==' is ambiguous on operands of type 'Vector2' and 'Vector3' 1 Answer

Regarding transform.position in the roll a ball tutorial 0 Answers

How to properly make an object follow the edge of another object? 0 Answers

Movement Sticking 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