Skip to content

Instantly share code, notes, and snippets.

View Doprez's full-sized avatar
⚠️
Not a real dog!

Doprez

⚠️
Not a real dog!
View GitHub Profile
@Doprez
Doprez / ConversionTest.cs
Last active June 24, 2024 05:12
Testing faster conversion methods between different C# math libraries.
using BenchmarkDotNet.Attributes;
using NVector3 = System.Numerics.Vector3;
using SVector3 = Stride.Core.Mathematics.Vector3;
using MVector3 = Microsoft.Xna.Framework.Vector3;
using MMatrix = Microsoft.Xna.Framework.Matrix;
using NMatrix = System.Numerics.Matrix4x4;
using SMatrix = Stride.Core.Mathematics.Matrix;
using NQuaternion = System.Numerics.Quaternion;
using MQuaternion = Microsoft.Xna.Framework.Quaternion;
using SQuaternion = Stride.Core.Mathematics.Quaternion;
using BepuPhysics;
using BepuPhysics.Collidables;
using BepuPhysics.CollisionDetection;
using Stride.BepuPhysics.Components;
using Stride.BepuPhysics.Definitions;
using Stride.BepuPhysics.Definitions.Contacts;
using Stride.Core;
using Stride.Core.Extensions;
using Stride.Core.Mathematics;
using Stride.Engine;
@Doprez
Doprez / SmoothFollowAndRotate.cs
Created April 7, 2024 21:54
Fixes jitter found in the default templates due to the camera being directly attached to a physics component.
[ComponentCategory("Utils")]
[DataContract("SmoothFollowAndRotate")]
public class SmoothFollowAndRotate : SyncScript
{
public Entity EntityToFollow { get; set; }
public float Speed { get; set; } = 1;
public override void Update()
{
var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;
@Doprez
Doprez / MeshExtensions.cs
Created November 11, 2023 05:10
Get Vertices and Indices from a mesh in Stride3d
using Stride.Games;
using Stride.Rendering;
using System;
using Stride.Core.Serialization;
using Stride.Core;
using Stride.Physics;
using System.Collections.Generic;
using Stride.Core.Mathematics;
public static class MeshExtensions
@Doprez
Doprez / SmoothRotate.cs
Last active June 2, 2023 13:16
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
@Doprez
Doprez / CreateButtons.cs
Created April 30, 2023 17:26
This is how I create buttons at runtime for a basic inventory system.
public void InitializeOtherInventory()
{
// InventoryPage is a variable assigned through the Stride GameStudion of type UIPage
var inventoryStack = InventoryPage.Page.RootElement.FindVisualChildOfType<ScrollViewer>("OtherItems")
.FindVisualChildOfType<StackPanel>();
// Clear the current list of buttons
inventoryStack.Children.Clear();
// Run GetInventoryButton and add it to the list of reach item
@Doprez
Doprez / SmoothFollow.cs
Created April 30, 2023 16:01
I use this to fix an issue where if a camera is attached to a physics component it creates an annoying stutter when moving.
[DataContract(nameof(SmoothFollow))]
[ComponentCategory("Animation")]
public class SmoothFollow : SyncScript
{
public Entity EntityToFollow { get; set; }
public Vector3 Speed { get; set; } = new Vector3(1, 1, 1);
public override void Update()
{
@Doprez
Doprez / AnimationEvent.cs
Created April 29, 2023 21:19
Stride Animation event trigger
using ImmoApocalypse.Code.Core.Structs;
using Stride.Core;
using Stride.Engine;
using System;
using System.Windows.Media.Animation;
namespace Core;
[DataContract(nameof(AnimationEvent))]
[AllowMultipleComponents]