Godot Version
4.2.1
I’m having a bit of an issue right now that I could use some advice on. I’ve got a CharacterBody3D player instance in my level scene, and ideally I’d like it to start where I place it, but it always starts at 0,0,0 whenever the game is run. I can go into the player scene and modify the position there, and the changes will take effect when I run the game, but moving the instance itself has no effect. There’s nothing in my code that directly sets the player’s position, so I’m really not sure why this is happening. I’ve got other instances of scenes in my level that don’t have this behavior, it seems to only affect the player. Is there some quirk to CharacterBody3D that I’m missing?
Additionally, I tested the player in a totally new level as well, just to rule out the possibility of something in the scene being the culprit, but I still encountered the same issue.
Here’s the code I’m using for my character movement:
//Get our input direction, and handle movement/deceleration
Vector2 inputDirection = Input.GetVector("Left", "Right", "Forward", "Back");
Vector3 targetDirection = (Transform.Basis * new Vector3(inputDirection.X, 0, inputDirection.Y)).Normalized();
direction = direction.Lerp(targetDirection, moveLerpSpeed * (float)delta);
if (direction != Vector3.Zero)
{
newVelocity.X = direction.X * currentSpeed;
newVelocity.Z = direction.Z * currentSpeed;
}
else
{
newVelocity.X = Mathf.MoveToward(newVelocity.X, 0, currentSpeed);
newVelocity.Z = Mathf.MoveToward(newVelocity.Z, 0, currentSpeed);
}
Velocity = newVelocity;
MoveAndSlide();