This is about grid based movement. I’m trying to move a character from unit 1 to unit 5 with a smooth movement. I already have a nice script that shoots a ray on a plane that also works out the gridSpacing, so I always get values back like 0, 4 or 5, 2, etc.
Still have a couple of problems achieving the rest though:
If I’m using lerp with time.deltaTime and trigger the movement through if target.x > player.x, I always end up with values like 4.9996 or something like that. I absolutely need the player to move to precise values. I thought I could use a Mathf.Round at the end of it, but I wasn’t yet able to figure out what the code should look like to make that happen.
Using lerp, I get a slowdown effect. The player starts moving and the closer he gets to the target, the more he slows down. Ultimately it takes him a ton of time to actually stop at the target. I want to be able to define the walkSpeed and the players movement should always be based on that.
Would be great if you guys could help me out on this one. I’m having a very hard time trying to figure out how to get this to work. Btw, I’m using JavaScript.
Statement, this works great, the only problem left is that there’s still a speedup from the Time.deltaTime * speed - so if I move something from the bottom left of the screen to the top right, it speeds up considerably in the middle and stops abruptly at the top.
Is there a smart way of having the units speed always stay the same while moving?