Spaces:
Runtime error
Runtime error
File size: 1,638 Bytes
ac55997 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
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;
}
}
}
}
|