I’ve just started messing around with moving cubes on a plane in response to keyboard input. I’m trying to keep things simple with no physics, movement of 1 metre/unit at a time etc. Think Frogger
In Update(), I’m calling GetKeyDown and if an arrow key is pressed, calculating a new Vector3 for the target position and then calling Lerp.
transform.position = Vector3.Lerp (transform.position, target, (Time.time - startTime) / duration);
This works well and my cube slides in the desired direction.
I now want to make the cube “hop” in the air by applying a sin offset to my transform.position.y, but just can’t figure it out. I think I need to track my movement lerp value in either X (for left/right movement) or Z (for north/south movement). From that, I somehow need to multiply by sin or cos to get the Y offset, then apply it to the transform.
Any thoughts or two-line code samples appreciated. I do intend to look at CharacterController tonight btw.