custom-chatbot / data /Traktor.User.cs
fastx's picture
Upload 84 files
ac55997
raw
history blame
1.64 kB
using System;
using System.Collections.Generic;
using Photon.Deterministic;
namespace Quantum
{
unsafe partial struct Traktor
{
public void Update(FrameThreadSafe frame, ref TraktorInputSystem.Filter filter, Input input)
{
TraktorConfig config = frame.FindAsset<TraktorConfig>(Config.Id);
ChainSystem.Filter sphereData = default;
var getter = frame.ComponentGetter<ChainSystem.Filter>();
;
if (getter.TryGet(frame, Sphere, &sphereData))
{
FPVector2 direction = input.Direction;
FPVector3 forward = filter.Transform->Forward;
FPVector3 right = filter.Transform->Right;
FP forwardSpeed = FPVector3.Dot(forward, sphereData.Body->Velocity);
// now rotate
FP lateralForce = config.LateralForce.Evaluate(forwardSpeed / config.MaxSpeed);
if (direction.X != 0)
{
FP rotationFactor = lateralForce * config.RotationMultiplier * direction.X;
filter.Transform->Rotate(FP._0, rotationFactor * frame.DeltaTime, FP._0);
}
FPVector3 force = default;
if (direction.Y > 0)
{
force += direction.Y * forward * config.Acceleration;
}
FP slipSpeed = FPVector3.Dot(right, sphereData.Body->Velocity);
force += right * slipSpeed * config.LateralForceMultiplier;
// swizzle from 2D to 3D
sphereData.Body->AddForce(force);
// snap to sphere position
filter.Transform->Position = sphereData.Transform->Position;
filter.Transform->Rotation = filter.Transform->Rotation.Normalized;
}
}
}
}