private Vector3 GetGravity(Entity entity, DefStDodgeOnGroundSettings setting) { if (setting.GravityGravityType == GravityType.Custom) { return(setting.Gravity); } if (setting.GravityGravityType == GravityType.Default) { return(m_CachedDefaultGravity); } if (EntityManager.HasComponent <StGravitySettings>(entity)) { var data = EntityManager.GetComponentData <StGravitySettings>(entity); return(data.FlagIsDefault == 1 ? m_CachedDefaultGravity : data.Value); } return(m_CachedDefaultGravity); }
private void ProcessPhysicItem ( float dt, ref DefStDodgeOnGroundSettings settings, ref DefStDodgeInput input, ref DefStDodgeOnGroundProcessData process, ref StVelocity velocity, ref CharacterControllerState state ) { /*if (!state.IsGrounded() && math.any(process.Direction != float3.zero) && process.IsDodging == 1) * { * var previousVelocity = velocity.Value; * var previousFlatVel = previousVelocity.ToGrid(1); * var previousSpeed = Mathf.Max(previousFlatVel.magnitude, settings.MinSpeed) + (process.InertieDelta * dt); * * velocity.Value = math.normalize(process.Direction) * previousSpeed; * velocity.Value.y = previousVelocity.y; * }*/ // TODO: Remove hardcoded character slopelimit (45) /*if (MvUtils.OnGround(state, velocity) && Vector3.Angle(state.AngleDir, Vector3.up) < 45 && process.IsDodging == 1) * { * process.IsDodging = 0; * * var oldY = velocity.Value.y; * var addSpeed = Mathf.Max(velocity.Value.ToGrid(1).magnitude - process.StartAfterDodgeFlatSpeed, 0); * var speed = Mathf.Min(velocity.Value.ToGrid(1).magnitude, process.StartFlatSpeed + addSpeed); * * velocity.Value = velocity.Value.ToGrid(1).normalized * speed; * * Debug.Log("nice"); * * velocity.Value.y = oldY; * }*/ process.InertieDelta -= state.IsGrounded() ? dt * 50f : dt; process.CooldownBeforeNextDodge -= dt; input.TimeBeforeResetState -= dt; }
private bool ProcessItem ( ref Entity entity, ref StVelocity velocity, ref DefStRunInput runInput, ref DefStDodgeOnGroundSettings setting, ref DefStDodgeInput input, ref DefStDodgeOnGroundProcessData process, ref CharacterControllerState state, Transform transform ) { var doDodge = input.State != InputState.None && process.CooldownBeforeNextDodge <= 0f && MvUtils.OnGround(state, velocity); if (input.TimeBeforeResetState <= 0f) { input.State = InputState.None; } // We expect the developpers to check for staminas or things like that for this command. EntityManager.SetComponentData(m_CmdDoDodge, new EntityCommandTarget(entity)); DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, doDodge, CmdState.Begin); doDodge = GetCmdResult(m_CmdDoDodgeResult); if (!doDodge) { return(false); } process.StartFlatSpeed = velocity.Value.ToGrid(1).magnitude; var direction = SrtComputeDirection(transform.forward.normalized, transform.rotation, runInput.Direction); velocity.Value.y = 0f; var addVelocity = SrtDodge(velocity.Value, direction, setting.AdditiveSpeed, setting.MinSpeed, setting.MaxSpeed); var momentum = transform.GetComponent <CharacterControllerMotor>().Momentum; if (Vector3.Dot(velocity.Value.normalized, math.normalizesafe(addVelocity)) >= 0.9f) { addVelocity = (momentum.normalized + ((Vector3)addVelocity).normalized).normalized * math.length(addVelocity); Debug.Log(addVelocity); } velocity.Value = addVelocity; velocity.Value += Vector3.up * setting.VerticalPower; input.TimeBeforeResetState = -1f; input.State = InputState.None; process.CooldownBeforeNextDodge = 0.5f; process.InertieDelta = 0.1f; process.Direction = direction; process.IsDodging = 1; process.StartAfterDodgeFlatSpeed = velocity.Value.ToGrid(1).magnitude; // We except developpers to just clean the pre-command phase, and not applying things like reducing stamina... DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, true, CmdState.End); // Send dodge message to clients BroadcastNewEntity(PostUpdateCommands, true); PostUpdateCommands.AddComponent(new DefStDodgeEvent(Time.time, Time.frameCount, entity)); MvDelegateEvents.InvokeCharacterDodge(entity); return(true); }
public override void Create(Entity entity) { Debug.Assert(GameObject != null, "GameObject != null"); Debug.Assert(GameObjectEntity.Entity == entity, "GameObjectEntity.Entity == entity"); var characterController = GameObject.GetComponent <CharacterController>(); characterController.center = Vector3.up * 0.9f; characterController.radius = 0.4f; characterController.stepOffset = 0.4f; characterController.height = 2f * 0.9f; characterController.slopeLimit = 75; characterController.detectCollisions = false; AddDefaultComponents(entity); if (Player.IsCreated) { EntityManager.AddComponentData(entity, new CharacterPlayerOwner { Target = Player.WorldPointer }); } EntityManager.AddComponentData(entity, new CharacterControllerState(false, false, false, Vector3.up)); EntityManager.AddComponentData(entity, StormiumCharacterMvData.NewBase()); EntityManager.AddComponentData(entity, new StormiumCharacterMvProcessData()); ShareManager.SetShareOption(entity, typeof(CharacterPlayerOwner), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(CharacterControllerState), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(StormiumCharacterMvData), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(StormiumCharacterMvProcessData), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); /*// Add switcher * { * var actionEntity = EntityManager.CreateEntity * ( * typeof(StActionTag), * typeof(StActionOwner), * typeof(StActionSlot), * typeof(StActionDualSwitch) * ); * * var actionType = typeof(StActionDualSwitch); * * EntityManager.SetComponentData(actionEntity, new StActionTag(TypeManager.GetTypeIndex(actionType))); * EntityManager.SetComponentData(actionEntity, new StActionOwner(entity)); * EntityManager.SetComponentData(actionEntity, new StActionSlot(0)); * EntityManager.SetComponentData(actionEntity, new StActionDualSwitch(rocketEntity, rocketEntity)); * * EntityManager.GetBuffer<StActionContainer>(entity).Add(new StActionContainer(actionEntity)); * } * // Add grenade * { * var actionEntity = EntityManager.CreateEntity * ( * typeof(StActionTag), * typeof(StActionOwner), * typeof(StActionSlot), * typeof(StActionAmmo), * typeof(StActionAmmoCooldown), * typeof(StDefActionThrowGrenade) * ); * * var actionType = typeof(StDefActionThrowGrenade); * * EntityManager.SetComponentData(actionEntity, new StActionTag(TypeManager.GetTypeIndex(actionType))); * EntityManager.SetComponentData(actionEntity, new StActionOwner(entity)); * EntityManager.SetComponentData(actionEntity, new StActionSlot(1)); * EntityManager.SetComponentData(actionEntity, new StActionAmmo(0, 1, 0)); * EntityManager.SetComponentData(actionEntity, new StActionAmmoCooldown(-1, 8)); * EntityManager.SetComponentData(actionEntity, new StDefActionThrowGrenade(28f, 25, 2)); * * EntityManager.GetBuffer<StActionContainer>(entity).Add(new StActionContainer(actionEntity)); * }*/ // Add transforms component EntityManager.AddComponentData(entity, new Position()); EntityManager.AddComponentData(entity, new Rotation()); EntityManager.AddComponentData(entity, new StVelocity()); ShareManager.SetShareOption(entity, typeof(Position), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(Rotation), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(StVelocity), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); // Add settings EntityManager.AddComponentData(entity, new EntityPhysicLayer(30)); EntityManager.AddComponentData(entity, new StStamina(4, 0.75f, 0)); EntityManager.AddComponentData(entity, DefStGroundRunSettings.NewBase()); EntityManager.AddComponentData(entity, DefStAerialRunSettings.NewBase()); EntityManager.AddComponentData(entity, DefStJumpSettings.NewBase()); EntityManager.AddComponentData(entity, DefStDodgeOnGroundSettings.NewBase()); EntityManager.AddComponentData(entity, new DefStJumpStaminaUsageData() { Usage = EStaminaUsage.RemoveStamina, RemoveBySpeedFactor01 = 0.01f, BaseRemove = 0.1f }); EntityManager.AddComponentData(entity, new DefStDodgeStaminaUsageData() { Usage = EStaminaUsage.BlockAction, Needed = 1f, BaseRemove = 1f }); ShareManager.SetShareOption(entity, typeof(EntityPhysicLayer), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(StStamina), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStGroundRunSettings), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStAerialRunSettings), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStJumpSettings), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStDodgeOnGroundSettings), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStJumpStaminaUsageData), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStDodgeStaminaUsageData), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); // Add simple client inputs EntityManager.AddComponentData(entity, new DefStRunClientInput()); EntityManager.AddComponentData(entity, new DefStJumpClientInput()); EntityManager.AddComponentData(entity, new DefStDodgeClientInput()); EntityManager.AddComponentData(entity, new DefStEntityAimClientInput()); ShareManager.SetShareOption(entity, typeof(DefStRunClientInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStJumpClientInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStDodgeClientInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStEntityAimClientInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); // Add global inputs EntityManager.AddComponentData(entity, new DefStRunInput()); EntityManager.AddComponentData(entity, new DefStJumpInput()); EntityManager.AddComponentData(entity, new DefStDodgeInput()); EntityManager.AddComponentData(entity, new DefStEntityAimInput()); ShareManager.SetShareOption(entity, typeof(DefStRunInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStJumpInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStDodgeInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStEntityAimInput), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); // Add processable data EntityManager.AddComponentData(entity, new DefStJumpProcessData()); EntityManager.AddComponentData(entity, new DefStDodgeOnGroundProcessData()); EntityManager.AddComponentData(entity, new DefStWallJumpProcessData()); EntityManager.AddComponentData(entity, new DefStWallDodgeProcessData()); ShareManager.SetShareOption(entity, typeof(DefStJumpProcessData), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStDodgeOnGroundProcessData), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(DefStWallDodgeProcessData), ComponentShareOption.Manual, DeliveryMethod.ReliableOrdered); // Make the clients able to change the input data EntityManager.AddComponentData(entity, new ClientDriveData <DefStRunInput>(Player)); EntityManager.AddComponentData(entity, new ClientDriveData <DefStJumpInput>(Player)); EntityManager.AddComponentData(entity, new ClientDriveData <DefStDodgeInput>(Player)); EntityManager.AddComponentData(entity, new ClientDriveData <DefStEntityAimInput>(Player)); ShareManager.SetShareOption(entity, typeof(ClientDriveData <DefStRunInput>), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(ClientDriveData <DefStJumpInput>), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(ClientDriveData <DefStDodgeInput>), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); ShareManager.SetShareOption(entity, typeof(ClientDriveData <DefStEntityAimInput>), ComponentShareOption.Automatic, DeliveryMethod.ReliableOrdered); }
private bool ProcessItem ( ref Entity entity, ref StVelocity velocity, ref DefStDodgeOnGroundSettings setting, ref DefStRunInput runInput, ref DefStDodgeInput input, ref DefStWallDodgeProcessData process, ref DefStDodgeOnGroundProcessData groundProcess, CharacterControllerMotor motor ) { var action = input.State != InputState.None && !MvUtils.OnGround(motor, velocity) && Time.time > process.TimeBeforeNextWD; DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.Begin); if (!m_CmdDoDodgeResult.GetComponentData <EntityCommandResult>().AsBool()) { DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.End); return(false); } var originalVelocity = velocity.Value; var fwd = motor.transform.forward; var pos = motor.transform.position + new Vector3(0, motor.CharacterController.stepOffset + 0.1f); var rot = motor.transform.rotation; var rd = motor.CharacterController.radius + 0.075f; var sw = motor.CharacterController.skinWidth + 0.025f; var height = motor.CharacterController.height - motor.CharacterController.stepOffset; var subheight = (height * 0.75f) - 0.005f; CPhysicSettings.Active.SetGlobalCollision(motor.gameObject, false); var direction = (Vector3)SrtComputeDirection(fwd, rot, runInput.Direction); direction = (velocity.Value.ToGrid(1).normalized + direction * 2).normalized; var rayTrace = UtilityWallRayTrace.RayTrace(ref direction, ref pos, ref rd, ref sw, ref height, ref subheight, motor.CharacterController); CPhysicSettings.Active.SetGlobalCollision(motor.gameObject, true); var success = rayTrace.normal != Vector3.zero && Mathf.Abs(rayTrace.normal.y) < 0.2f; if (success) { rayTrace.normal = rayTrace.normal.ToGrid(1).normalized; var reflected = (Vector3.Reflect(direction, rayTrace.normal) + rayTrace.normal).normalized; var oldY = velocity.Value.y; var dirInertie = (reflected * (velocity.Value.magnitude + 1)) + rayTrace.normal * 3.5f; dirInertie = RaycastUtilities.SlideVelocityNoYChange(velocity.Value, rayTrace.normal) + rayTrace.normal * 10; var minSpeed = Mathf.Max(velocity.Value.ToGrid(1).magnitude + setting.AdditiveSpeed, setting.MinSpeed); velocity.Value = dirInertie.ToGrid(1).normalized *(minSpeed); velocity.Value.y = Mathf.Max(oldY + 2, 0); process.TimeBeforeNextWD = Time.time + DefaultCooldown; input.TimeBeforeResetState = -1f; input.State = InputState.None; groundProcess.CooldownBeforeNextDodge = 0.25f; //groundProcess.InertieDelta = 0.5f; groundProcess.Direction = dirInertie.normalized; BroadcastNewEntity(PostUpdateCommands, true); PostUpdateCommands.AddComponent(new DefStWallJumpEvent(Time.time, Time.frameCount, entity, originalVelocity, rayTrace.normal)); } DiffuseCommand(m_CmdDoDodge, m_CmdDoDodgeResult, action, CmdState.End); return(success); }