- Home /
Assigning valid moves
Hi guys i am making a board game same as checkers.i have added an empty object to all the points where player can move and added a box collider to each empty object.And attached a click to move script to each player token.Now i want to assign valid moves.e.g. as shown in picture... Players can only move on vertex of each square.Player can only move to adjacent vertex.Thus it can only move from red spot to yellow and cannot move to blue spot.Also there is one condition that if at yellow spot there is token of another player than player cannot move to that spot instead it will have to go from red to green spot.So please tell me how to assign a valid position where a player can click and move by scripting.
I have another problem with click to move.When i click all the objects move to that position.But i only want to move a single token.So what can i add to script to select a specific object and then click to move the specific object.Here is my script for click to move.`
var obj:Transform;
private var hitPoint : Vector3;
private var move: boolean = false;
private var startTime:float;
var speed = 1;
function Update ()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var hit : RaycastHit; // no point storing this really
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, 10000))
{
hitPoint = hit.point;
move = true;
startTime = Time.time;
}
}
if(move)
{
obj.position = Vector3.Lerp(obj.position, hitPoint, Time.deltaTime * speed);
if(obj.position == hitPoint)
{
move = false;
}
}
}`
What if you added a script, that activates certain pieces when you click them? So, if you want to move, piece "a", click it to activate it. Then click the spot to move to. So that all others are deactivated when you move piece "a".
thats what i m asking for ..what is the code to select an object?