public override void _Process(float delta) { loopCount++; var localRight = Transform.basis.Column0; var localUp = Transform.basis.Column1; var localFwd = Transform.basis.Column2; Translate(Vector3.Forward * delta * 10); //var targetDiff = GlobalTransform.origin - steerTarget; var desiredXform = GlobalTransform.LookingAt(steerTarget, Vector3.Up); GlobalTransform = GlobalTransform.InterpolateWith(desiredXform, 1f * delta); // Transform.Rotated(Vector3.Up) //Transform. //Transform.InterpolateWith if (loopCount % 100 == 0) { GD.Print($"{loopCount / 100}: localFwd={localFwd.ToString("F2")}"); } //Transform.InterpolateWith //GD.Print("steerTarget", steerTarget); }
public override void _PhysicsProcess(float delta) { if (AI == null) { return; } AI(); //move if (WayPoint == null) { MoveCharacter(delta, new Vector3()); return; } //rotate RotateObjectLocal(Vector3.Up, Mathf.Pi); var rot = GlobalTransform.LookingAt(EnemyBody.GlobalTransform.origin, new Vector3(0, 1, 0)).basis.GetEuler(); if (Mathf.Abs(Transform.basis.GetEuler().y - rot.y) > Mathf.Pi) { if (rot.y < 0) { rot.y += 2 * Mathf.Pi; } else { rot.y -= 2 * Mathf.Pi; } } rot = Rotation.LinearInterpolate(rot, delta * RotateSpeed) - Transform.basis.GetEuler(); rot.y = Mathf.Clamp(rot.y, -1, 1); RotateObjectLocal(Vector3.Up, rot.y); RotateObjectLocal(Vector3.Up, Mathf.Pi); //movement var dist = WayPoint.GlobalTransform.origin - GlobalTransform.origin; if (Mathf.Sqrt(Mathf.Pow(dist.x, 2) + Mathf.Pow(dist.z, 2)) < Resources.WaypointDistance) { MoveCharacter(delta, new Vector3()); return; } var movement = new Vector3(Mathf.Clamp(dist.x, -1, 1), 0, Mathf.Clamp(dist.z, -1, 1)); MoveCharacter(delta, movement); //makes sure everything is unchanged Orthonormalize(); AnimTree.Advance(delta); }