Created
November 1, 2023 04:55
-
-
Save LionGet/32e12422ca2ff71356e3bff0f3e71f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using { /Fortnite.com/Devices } | |
using { /Fortnite.com/Game } | |
using { /Fortnite.com/Characters } | |
using { /Verse.org/Simulation } | |
using { /UnrealEngine.com/Temporary/SpatialMath } | |
moving_direction := enum: | |
None | |
Front | |
Back | |
Left | |
Right | |
player_state:=class<unique>: | |
var MaybeGamePlayer:?game_player=false | |
var MovingDirection:moving_direction=moving_direction.None | |
var PositionOld:vector3=vector3{} | |
Init(Gamer:game_player):void= | |
Print("Player State Initialization") | |
set MaybeGamePlayer = option{Gamer} | |
if(Agent:=agent[Gamer.Player],FortChar:=Agent.GetFortCharacter[]): | |
if(FortChar.IsActive[]): | |
spawn{GetMoveDir(Agent)} | |
Print("Spawned get positional") | |
else: | |
Print("FortChar is not active") | |
GetMoveDir(Agent:agent)<suspends>:void= | |
if(FortChar:=Agent.GetFortCharacter[]): | |
loop: | |
Sleep(0.0) | |
PlayerPosition := FortChar.GetTransform().Translation | |
PlayerRotation := FortChar.GetTransform().Rotation | |
FacingVector := PlayerRotation.GetLocalForward() | |
StrafingVector := PlayerRotation.GetLocalRight() | |
Vector := PlayerPosition - PositionOld | |
VectorDistance := DistanceXY(PlayerPosition,PositionOld) | |
if: | |
NormalizedPosition := Vector.MakeUnitVector[] | |
NormalizedForward := FacingVector.MakeUnitVector[] | |
NormalizedRight := StrafingVector.MakeUnitVector[] | |
VectorDistance <> 0.0 | |
then: | |
Direction := DotProduct(NormalizedPosition,NormalizedForward) | |
StrafeDir := DotProduct(NormalizedPosition,NormalizedRight) | |
# Print("Strafe is {StrafeDir}") | |
if: | |
DirectionRound := Round[Direction] | |
StrafeRound := Round[StrafeDir] | |
then: | |
if(DirectionRound = 1): | |
if(MovingDirection <> moving_direction.Front): | |
set MovingDirection = moving_direction.Front | |
else if(DirectionRound = -1): | |
if(MovingDirection <> moving_direction.Back): | |
set MovingDirection = moving_direction.Back | |
else if(StrafeRound = 1): | |
if(MovingDirection <> moving_direction.Right): | |
set MovingDirection = moving_direction.Right | |
else if(StrafeRound = -1): | |
if(MovingDirection <> moving_direction.Left): | |
set MovingDirection = moving_direction.Left | |
else: | |
set MovingDirection = moving_direction.None | |
set PositionOld = PlayerPosition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment