noob question :)

I need to move my object smoothly and strongly by 1 unit(meter) and no more =) As example;when im holding down “UP” key my object interpolate by 1 unit up , and on …If i release UParrow button, object stop when arrived nearest destination.So i need character control(without character controller,rigidbodies or colliders) like “Bobmerman” and i need grid movement,only by 1+ unit up down right or left .Thanks for help :stuck_out_tongue:

Hmmmm, sounds like a fun scripting challenge…
Maybe I can help, but there is no guarantee :slight_smile:

Try checking the values of Input.GetButtonDown (“Horizontal”) and Input.GetButtonDown (“Vertical”) in an Update () function. These axes should refer to the arrow and WASD keys.

Then, start a ‘character move’ coroutine if one of the Inputs returns true. At the start of the coroutine, check the value of Input.GetAxisRaw (“Horizontal”) or Input.GetAxisRaw (“Vertical”), whichever one is appropriate, to decide in what direction the character should move. The next part of the coroutine animates the character moving a distance of 1 meter in the appropriate direction.

Hope this helps you with getting started.

-Dan

Thank you :slight_smile: But i dont know how to write a java code ,i need exactly per 1 unit movement in 2D.For example,if i press “right” my “character” move by 1 unit right(+x) direction,after start checking : if “right” still pressed ->“character” continue moving right over time…consequently “character” always got Int coordinates.I think this must look approximately so
Cube is me character
function Start(){
CubeStartPosition=transform.position;
}
function Update(){
h=Input.GetAxisRaw(“Horizontal”);
v=Input.GetAxisRaw(“Vertical”);
if (h!=0 v==0 )
newX=CubeStartPosition.x+1*h;
else if (h==0 v!=0 )

newZ=CubeStartPosition.z+1*v;
NewPosition=Vector3(newX,0,newZ);

And here i dont know hot to interpolate
from CubeStartPosition to NewPosition and finish interpolation when current position became equal to NewPosition
Im trying to
currentPos=transform.position;
while(currentPos != NewPosition)
{
transform.Translate(transform.position-newPosition)
currentPos=transform.position;
yield;
}
But this is wrong,coordinates become not integer,but i need Exactly “grid” movement by 1 unit no more no less ,like my character grid snapped :roll:

You may find this useful: http://unifycommunity.com/wiki/index.php?title=AniMate

This is what I chose to use in similar case, just because it is so nice and clean :slight_smile:

Many thanks !! :stuck_out_tongue: