public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; ActorHeader.GroundHit Ground = Actor.Ground; Vector3 Velocity = Actor._velocity; bool JumpRequest = (_args.ActionFlags & (1 << 2)) != 0; if (Actor.SnapEnabled && Ground.stable && JumpRequest) { // Eliminate Y-component of our velocity and instead set it to whatever we'd like: Velocity[1] = Mathf.Sqrt(2 * (_args.Gravity * _args.GravitationalMultiplier) * JumpHeight); // We're only doing this since gravitational movement / vertical movement is always // 100% in the 2nd component of our velocity. We'll never be implementing spherical gravity // or anything like that as of this moment. Changing it won't be hard either if we // ever want this functionality. Actor.SetSnapEnabled(false); // disabling snapping until we've found the ground again Cursor.lockState = CursorLockMode.Locked; TimeJumpSnapshot = GlobalTime.T; _args.AssignHold(WaitToSnapUntil); // wait a few milliseconds to begin snapping again } Actor.SetVelocity(Velocity); }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; ActorHeader.GroundHit Ground = Actor.Ground; // Ground is currently last frame as we have not moved until ActorMove() of this simulation ActorHeader.GroundHit LastGround = Actor.LastGround; // LastGround is the frame prior to the last Vector3 _v = Actor._velocity; bool _applyfriction = _v.sqrMagnitude > 0F; if (!_applyfriction) { return; } LastGroundSnapshot = (Ground.snapped && !LastGround.snapped) ? GlobalTime.T : LastGroundSnapshot; float _vm = _v.magnitude; // Determine whether to apply ground friction or air friction bool _applygroundfriction = (Actor.SnapEnabled && Ground.stable) && (GlobalTime.T - LastGroundSnapshot) > GroundFrictionLeeway; if (_applygroundfriction) { BehaviourHeader.ApplyFriction(ref _v, _vm, GroundFriction, GlobalTime.FDT); } else { BehaviourHeader.ApplyFriction(ref _v, _vm, AirFriction, GlobalTime.FDT); } Actor.SetVelocity(_v); }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; Vector3 Velocity = Actor._velocity; Vector3 Wish = _args.ViewWishDir; //BehaviourHeader.DetermineWishVelocity(ref Velocity, Wish, MaximumFlySpeed, FlyAcceleration * GlobalTime.FDT); BehaviourHeader.ApplyAcceleration(ref Velocity, Wish, MaximumFlySpeed, FlyAcceleration); BehaviourHeader.ApplyFriction(ref Velocity, Velocity.magnitude, FlyAirFriction, GlobalTime.FDT); Actor.SetVelocity(Velocity); }
public override void Simulate(EnemyArgs _args) { ActorHeader.Actor _actor = _args.Actor; UnityEngine.Transform _self = _args.Self; _actor.SetPosition(_self.position); _actor.SetOrientation(_self.rotation); ActorHeader.Move(this, _actor, GlobalTime.FDT); _self.SetPositionAndRotation(_actor._position, _actor._orientation); }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; UnityEngine.Transform Transform = _args.ActorTransform; Actor.SetPosition(Transform.position); Actor.SetOrientation(Transform.rotation); ActorHeader.Move(this, Actor, GlobalTime.FDT); Transform.SetPositionAndRotation(Actor._position, Actor._orientation); return; }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; ActorHeader.GroundHit Ground = Actor.Ground; Vector3 Velocity = Actor._velocity; bool _validgravity = Actor.Ground.stable; Velocity -= new Vector3(0, 1, 0) * (_args.Gravity * _args.GravitationalMultiplier * GlobalTime.FDT); Actor.SetVelocity(Velocity); return; }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; ActorHeader.GroundHit Ground = Actor.Ground; ActorHeader.GroundHit LastGround = Actor.LastGround; Vector3 Velocity = Actor._velocity; Vector3 Wish = _args.ViewWishDir; bool Grounded = Actor.SnapEnabled && Ground.stable; if (Grounded && !LastGround.stable) // Landing { VectorHeader.ClipVector(ref Velocity, Ground.normal); } // Orient Wish Velocity to grounding plane if (Grounded && OrientVelocityToGroundPlane) { VectorHeader.CrossProjection(ref Wish, new Vector3(0, 1, 0), Ground.normal); } else { // Clip Wish Velocity along upward plane if we're not orienting/stable as we may be able to fight gravity if not done VectorHeader.ClipVector(ref Wish, new Vector3(0, 1, 0)); Wish.Normalize(); } //if (Grounded) // Subtract max speed based on stability // BehaviourHeader.DetermineWishVelocity(ref Velocity, Wish, MaximumGroundMoveSpeed, GroundAcceleration * GlobalTime.FDT); //else // BehaviourHeader.DetermineWishVelocity(ref Velocity, Wish, MaximumAirMoveSpeed, AirAcceleration * GlobalTime.FDT); if (Grounded) { BehaviourHeader.ApplyAcceleration(ref Velocity, Wish, MaximumGroundMoveSpeed, GroundAcceleration); } else { BehaviourHeader.ApplyAcceleration(ref Velocity, Wish, MaximumAirMoveSpeed, AirAcceleration); } Actor.SetVelocity(Velocity); return; }
public override void Simulate(EnemyArgs _args) { if (_args.Target == null) { return; } ActorHeader.Actor _actor = _args.Actor; Vector3 _targetv3 = _args.Target.position; Vector3 _selfv3 = _args.Self.position; Vector3 _lookv3 = _targetv3 - _selfv3; _lookv3.Normalize(); _lookv3 *= 16F; //_lookv3 = Vector3.ClampMagnitude(_lookv3, 1.0F); _actor.SetVelocity(_lookv3); }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; ActorHeader.GroundHit Ground = Actor.Ground; Vector3 Forward = _args.ActorView.forward; Vector3 Wish = _args.ViewWishDir; bool Grounded = Actor.SnapEnabled && Ground.stable; bool DashRequest = (GlobalTime.T - DashRequestSnapshot) > 0.1F && DashStamina >= DashCost && (_args.ActionFlags & (1 << 3)) != 0; if (DashRequest) // valid dash { bool UseViewDir = Wish.sqrMagnitude == 0; // Completely eradicate all velocity Actor.SetVelocity(Vector3.zero); DashStamina -= DashCost; Vector3 DashDirection = UseViewDir ? Forward : Wish; VectorHeader.ClipVector(ref DashDirection, new Vector3(0, 1, 0)); DashDirection.Normalize(); DashRequestSnapshot = GlobalTime.T; _args.AssignHold(ApplyDashDuration); Actor.SetVelocity(DashDirection * DashVelocityDelta); DashEvents?.Invoke(_args, DashState.Enter); } else if (Grounded) // If we aren't actually dashing, let's rejuvenate our stamina if we're grounded. { DashStamina += DashGrowthRate * GlobalTime.FDT; DashStamina = Mathf.Min(DashStamina, DashCap); } }
public override void Simulate(ActorArgs _args) { ActorHeader.Actor Actor = _args.Actor; UnityEngine.Transform ViewTransform = _args.ActorView; bool Grounded = Actor.SnapEnabled && Actor.Ground.stable; Vector2 RawWish = _args.RawWishDir; float _visanglez = 0F; float _moveoffset = HandsOffset; if (Grounded) { _visanglez = -MaximumZTilt * RawWish[0]; } else { _visanglez = 0; } if (RawWish[1] != 0 && Grounded) { WishElapsed += GlobalTime.FDT; } else { WishElapsed = 0F; } LocalEulers[2] = LocalEulers[2] + (_visanglez - LocalEulers[2]) * (GlobalTime.FDT * 20F); _moveoffset += OffsetCurve.Evaluate(WishElapsed * SwaySpeed) * SwayDistance; LocalPosition[2] = LocalPosition[2] + (_moveoffset - LocalPosition[2]) * (GlobalTime.FDT * 20F); HandsTransform.localPosition = LocalPosition; CameraTransform.localRotation = Quaternion.Euler(LocalEulers); }
private void Start() { _actor = GetComponent <ActorHeader.Actor>(); _actor.SetMoveType(ActorHeader.MoveType.Slide); _actor.SetSnapType(ActorHeader.SlideSnapType.Toggled); _actor.SetSnapEnabled(true); // update actor state to transform state _actions.Add((_actor) => { CommandHeader.ApplyActorTransform(transform, _actor); return(true); }); // gravity _actions.Add((_actor) => { if (!_actor.Ground.stable) { _actor._velocity -= Vector3.up * 39.62F * GlobalTime.FDT; } return(true); }); // bounce determinism _actions.Add((_actor) => { if (_bouncecount <= 0) { _actor.SetVelocity(Vector3.zero); _actor.SetSnapEnabled(false); return(false); } else { if (_actor.Ground.stable) { _bouncecount--; _actor.SetSnapEnabled(false); _actor.SetVelocity(_actor.Ground.normal * (_bouncecount)); } return(true); } }); // snap detection procedure _actions.Add((_actor) => { if (_bouncecount <= 0) { return(false); } else { // wait at least two frames until we determine eligiblity to snap again. if (!_actor.Ground.stable && !_actor.LastGround.stable) { _actor.SetSnapEnabled(true); } return(true); } }); // move procedure _actions.Add((_actor) => { if (_bouncecount <= 0) { return(false); } else { ActorHeader.Move(this, _actor, GlobalTime.FDT); return(true); } }); // update transform state to actor state _actions.Add((_actor) => { CommandHeader.ApplyTransformActor(transform, _actor); return(true); }); }
public static void ApplyTransformActor(Transform _t, ActorHeader.Actor _a) { _t.position = _a._position; _t.rotation = _a._orientation; }