My CubeDude was turning too slow

My player was changing direction too slowly. For example, walking left and right looked like this:
TurnSlow

My solution was to look at not motion.x and .z times -speed, but times -speed * 100, or some other large number. This makes the character look at a far away point in the direction he is moving, and results in more instant turning like this:
TurnFast

There’s a sweet spot where he’s doing a little bit of a pivot when changing direction, rather than unrealistically snapping 180 degrees.

My final code looks like this:

func face_forward():
	var forward = motion * Vector3(-1, 0, -1) * speed * 5
	if forward.length() > EPSILON:
		look_at(forward, UP)

1 Like

It’s not that he’s moving too slow, he’s facing away from the center(ish, a position at (-SPEED, 0, -SPEED) * movement). You can test this by getting stuck in the goal.

If the SPEED (or a modifier, as you’ve used) is large enough the position gets outside the bonds of the pitch and works fine. If the pitch is large enough, I’d imagine we’d run into the same problem again. But I guess you could use a much larger modifier value and it would be ok.

I added the player’s position to the facing direction and it seems to work fine as well. I don’t know what the best solution is.

That means you’ve fixed the bug :slight_smile:
I made a post about this bug here: About 'Better CubeDude Movement'!
The problem is that in the video it is assumed that look_at() uses local space, but really it uses global space. So we have to add the global player position to the motion vector to make it work as intended.

Privacy & Terms