Skip to content

Instantly share code, notes, and snippets.

@Doprez
Last active June 2, 2023 13:16
Show Gist options
  • Save Doprez/5bd571341b075c5cf257d7265c374807 to your computer and use it in GitHub Desktop.
Save Doprez/5bd571341b075c5cf257d7265c374807 to your computer and use it in GitHub Desktop.
Smooth rotation to fix Stride Physics stutter when moving. This script mathces the rotation of another entity using Slerp.
using MagicAndMight.Code.Core.Extensions;
using Stride.Core;
using Stride.Core.Mathematics;
using Stride.Engine;
namespace MagicAndMight.Code.Core.Utils;
[DataContract(nameof(SmoothRotate))]
[ComponentCategory("Utils")]
public class SmoothRotate : SyncScript
{
public Entity EntityToFollow { get; set; }
public Vector3 Speed { get; set; } = new Vector3(1, 1, 1);
public override void Update()
{
var currentRotation = Entity.Transform.Rotation;
EntityToFollow.Transform.GetWorldTransformation(out var _, out var otherRotation, out var _);
Quaternion.Slerp(ref currentRotation, ref otherRotation, Speed.X * this.DeltaTime(), out var newRotation);
Entity.Transform.Rotation = newRotation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment