• 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 Vordas32 · Dec 07, 2012 at 10:59 AM · movementgameobjectlist

Moving player to other game objects board game

Hi developers,

I have one problem, for now, in my 3d Ludo board game that I want to create. Player is on waypoint_01 on begining of game. When i trow dice I now in code where he must to be and which waypoints must walk throu. So I have list of waypoints that he must walk throu to a destination. I want that player go on first waypoint which is in a list and wait for one seconds and than player go to a second wapoint in a list. So this will continuesly doing to a destination. I dont want to just jump to waypoint I want to be in movement when he goes from one waypoint to another in a list.

This is screenshot: Game Start

alt text

This is screenshot when I click play(Dice is trowen)

alt text

I found all yellow waypoints and sorted them in this script.

 var MainWaypoints:GameObject[];
 
 function Awake()
 {
     MainWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");
     
     SortArray(MainWaypoints);
     
     //Make all waypoints with tag name Waypoint yellow
     for (var waypoint:GameObject in MainWaypoints)
     {
         waypoint.renderer.material.color = Color.yellow;
     }
 }
 
 //Sort Waypoint Game Object Array from smaller number to the biggest number
 function SortArray (goArray:GameObject[]) 
 {
 var temp : GameObject;
    for(i = 0; i < goArray.length; i++) {
       for(j = i+1; j < goArray.length; j++) {
           if(String.Compare(goArray[i].name,goArray[j].name) > 0) {
              temp = goArray[i];  
              goArray[i] = goArray[j];
              goArray[j] = temp;
           }
      }
   }
 }


All brain code for trow dice and find waypoints that player must go throu is it in PlayerScript

 import System.Collections.Generic;
 
 var waypointScript:WaypointsScript;
 var TimeToPlayerWaitOnPoint:float = 1;
 var PlayerSpeed:float = 3;
 
 var ListOfWaypoints:List.<GameObject> = new List.<GameObject>();
 
 private var CubeMinNumber:float = 1;
 private var CubeMaxNumber:float = 6.4;
 private var CubeRandomNumber:float;
 private var CubeFinalNumber:int;
 private var PlayCubeIsPressed:boolean = false;
 
 private var CurrentWaypoint:int = 0;
 private var LastWaypoint:int = 0;
 
 private var WhileSecurity:int = 10;
 
 
 
 function Awake()
 {
     waypointScript = GameObject.FindWithTag("MainWaypoint").GetComponent(WaypointsScript);
 }
 
 function Start()
 {
     //Player is on position Waypoint_01 wher must start the game and is rotated like 
     //Waypoint_01(start position)
     transform.position = waypointScript.MainWaypoints[0].gameObject.transform.position;
     transform.eulerAngles.y = waypointScript.MainWaypoints[0].gameObject.transform.eulerAngles.y;
 }
 
 function Update () 
 {
     waypointScript.MainWaypoints[CurrentWaypoint].renderer.material.color = Color.red;
     
 }
 
 function OnGUI()
 {
     
     
     if (GUI.Button(Rect(10, 10, 100, 50), "Play"))
     {
         //Random number from 1 to 6.4 for a dice
         CubeRandomNumber = Random.Range(CubeMinNumber, CubeMaxNumber);
         //Restriction for dice
         CubeRandomNumber = Mathf.Clamp(CubeRandomNumber, 1, 6.4);
         
         //Final number of a dice. It is integer
         CubeFinalNumber = parseInt(CubeRandomNumber);
         
         //The Lastwaypoint it will be always a last position of where must be a player before 
         //trowing a dice
         LastWaypoint = CurrentWaypoint;
         print("Last Waypoint: "+LastWaypoint);
         
         //Definition of where a player must be when dice is trowen
         CurrentWaypoint += CubeFinalNumber;
         print("Current Waypoint: " + CurrentWaypoint);
         
         FindWaypointsWhichPlayerMustWalkthrou();
         
         PlayCubeIsPressed = true;
     }
     else
     {
         PlayCubeIsPressed = false;
     }
     
     
     
     GUI.TextField(Rect(10, 70, 25, 25), CubeFinalNumber.ToString());
         
 }
 
 function FindWaypointsWhichPlayerMustWalkthrou()
 {
     //The LastEaypoint is a point where player is currently now. The CurrentWaypoint is a point where
     //Player must to be when dice is trowen.
     
     if (LastWaypoint != CurrentWaypoint)
     {
         //When dice is trowed clear the list so that on new play dice play list
         //is populated with new waypoints
         ListOfWaypoints.Clear();
         
         //Loop for the Wayponits that player must walk started from one point front.
         for (var i:int = LastWaypoint + 1; i <= CurrentWaypoint; i++)
         {
             var temp:GameObject;
             
             temp = waypointScript.MainWaypoints[i];
             
             //This is all waypoints that the player has to walk
             ListOfWaypoints.Add(temp);
         }
     }
 }

I saw that movement from one position to another position can be done with Mathf.Lerp but I don't now how to implement this method in my scenario. I try in FOR Loop access all waypoints and in loop add Lerp but it's not working how it should be.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

moving starfield with gameobject prefab list 1 Answer

A node in a childnode? 1 Answer

Runtime instantiation based on XML 1 Answer

How to add and access objects in array? 1 Answer

Get first gameobject in a list and cycle through on keypress 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