I am trying to move a block to another blocks position, but the cube moves away from the other cube?
The line of code:
cube.transform.position = movePosBlock.transform.position;
Full Code:
if (Input.GetMouseButtonDown(1))
{
if (GameObject.Find("movePosBlock(Clone)") == null)
{
object mPB = Instantiate(movePosBlock, g, Quaternion.identity);
Vector3 moveTo = movePosBlock.transform.position;
stuartCharacter.transform.position = moveTo;
}
}
Any Help? :?
Store the position of the other cube before you start moving it then move to the stored position.
Doesn’t matter i fixed it, but how to i get the block to move to the position like a person is walking?
Mike_L
February 8, 2013, 10:58pm
5
you mean smoothly over time?
Yeah, that’s what i meant
Slev
February 8, 2013, 11:00pm
7
Multiply your transform by Time.deltaTime
could you give me an example:
This is the code i have:
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
Vector3 g = new Vector3(Mathf.Round(hit.point.x), Mathf.Ceil(hit.point.y), Mathf.Round(hit.point.z));
Cube.transform.position = g;
Slev
February 8, 2013, 11:12pm
9
Cube.transform.position = g * Time.deltaTime;
Perhaps have a look at iTween in the app store?
But you just play the animation while moving and make sure the speed is appropiate for the animation.
Work great, but how do i make it so it goes the speed the whole time it is moving because it kinda starts fast then slows down?
iTween.MoveTo(cube, g, 5);