コード例 #1
0
        internal override void Update(double elapsedTime, GameTime gameTime)
        {
            if (World.xwing == null)
            {
                return;
            }

            Vector3 difference = World.xwing.Position() - CannonsPosition;
            float   distance   = difference.Length();

            if (IsInRange(distance))
            {
                PhysicUtils.DirectionToEuler(difference, distance, out float objectiveYaw, out float objectivePitch);
                Aim(difference, objectiveYaw - headAngle, objectivePitch - cannonsAngle, elapsedTime);
                if (IsAimed(Math.Abs(objectiveYaw - headAngle), Math.Abs(objectivePitch - cannonsAngle)) && idleTime > MinIdleTime)
                {
                    Fire();
                    idleTime = 0;
                }
                else
                {
                    idleTime += elapsedTime;
                }
            }
            else
            {
                idleTime += elapsedTime;
            }
        }
コード例 #2
0
        protected override void Fire()
        {
            Vector3 forward = PhysicUtils.Forward(cannonsRotation);
            Vector3 left    = PhysicUtils.Left(cannonsRotation);

            World.InstantiateLaser(CannonsPosition - left, forward, cannonsRotation, emitter);
            World.InstantiateLaser(CannonsPosition + left, forward, cannonsRotation, emitter);
        }
コード例 #3
0
    public void Bounce(RaycastHit hit)
    {
        Vector3 VFBall = PhysicUtils.BounceFromPlane(Velocity, hit.normal);

        transform.position = hit.point;

        solverScript.setBallVelocity(VFBall);
    }
コード例 #4
0
        private void UpdateOrientation(BodyReference body)
        {
            Quaternion rotation = body.Pose.Orientation.ToQuaternion();

            forward        = -PhysicUtils.Forward(rotation);
            rightDirection = PhysicUtils.Left(rotation);
            upDirection    = PhysicUtils.Up(rotation);
        }
コード例 #5
0
        protected override void OnInstantiate()
        {
            BodyReference body = Body();

            System.Numerics.Vector3 velocity = PhysicUtils.Forward(body.Pose.Orientation.ToQuaternion()).ToBEPU() * linearVelocity;
            body.Velocity.Linear = velocity;

            engineSound          = TGCGame.content.S_TIEEngine.CreateInstance();
            engineSound.IsLooped = true;
            engineSound.Volume   = 0.001f;
            emitter.Velocity     = velocity.ToVector3();
            TGCGame.soundManager.PlaySound(engineSound, emitter);
        }
コード例 #6
0
        internal void Fire(double gameTime)
        {
            if (gameTime < lastFire + fireCooldownTime)
            {
                return;
            }

            BodyReference body             = Body();
            Vector3       position         = body.Pose.Position.ToVector3();
            Quaternion    laserOrientation = PhysicUtils.DirectionsToQuaternion(TGCGame.camera.MouseDirection(position), upDirection);

            World.InstantiateLaser(position, -forward, laserOrientation, emitter, laserVolume);
            lastFire = gameTime;
        }
コード例 #7
0
        public static Vector3 GetRandomPosition(Transform transform, GameAreaType type, float randomRadius, float squareWidth, float squareDepth, float squareHeight, RaycastHit[] findGroundRaycastHits, int groundLayerMask)
        {
            Vector3 randomedPosition = transform.position;

            switch (type)
            {
            case GameAreaType.Radius:
                randomedPosition += new Vector3(Random.Range(-1f, 1f) * randomRadius, 0, Random.Range(-1f, 1f) * randomRadius);
                break;

            case GameAreaType.Square:
                randomedPosition += new Vector3(Random.Range(-0.5f, 0.5f) * squareWidth, 0, Random.Range(-0.5f, 0.5f) * squareDepth);
                break;
            }
            return(PhysicUtils.FindGroundedPosition(randomedPosition, findGroundRaycastHits, squareHeight, groundLayerMask));
        }
コード例 #8
0
        public void FindAndSetBuildingAreaByAxes(Vector2 aimAxes)
        {
            int     tempCount   = 0;
            Vector3 tempVector3 = MovementTransform.position + (GameplayUtils.GetDirectionByAxes(CacheGameplayCameraTransform, aimAxes.x, aimAxes.y) * ConstructingBuildingEntity.buildDistance);

            switch (CurrentGameInstance.DimensionType)
            {
            case DimensionType.Dimension3D:
                tempCount = PhysicUtils.SortedRaycastNonAlloc3D(tempVector3 + (Vector3.up * 50f), Vector3.down, raycasts, 100f, CurrentGameInstance.GetBuildLayerMask());
                break;

            case DimensionType.Dimension2D:
                tempCount = PhysicUtils.SortedLinecastNonAlloc2D(tempVector3, tempVector3, raycasts2D, CurrentGameInstance.GetBuildLayerMask());
                break;
            }
            LoopSetBuildingArea(tempCount);
        }
コード例 #9
0
        public void FindAndSetBuildingAreaByMousePosition()
        {
            int     tempCount = 0;
            Vector3 tempVector3;

            switch (CurrentGameInstance.DimensionType)
            {
            case DimensionType.Dimension3D:
                tempCount = PhysicUtils.SortedRaycastNonAlloc3D(CacheGameplayCameraControls.CacheCamera.ScreenPointToRay(InputManager.MousePosition()), raycasts, 100f, CurrentGameInstance.GetBuildLayerMask());
                break;

            case DimensionType.Dimension2D:
                tempVector3 = CacheGameplayCameraControls.CacheCamera.ScreenToWorldPoint(InputManager.MousePosition());
                tempCount   = PhysicUtils.SortedLinecastNonAlloc2D(tempVector3, tempVector3, raycasts2D, CurrentGameInstance.GetBuildLayerMask());
                break;
            }
            LoopSetBuildingArea(tempCount);
        }
コード例 #10
0
        protected void Fire(BodyReference body, GameTime gameTime)
        {
            double totalTime = gameTime.TotalGameTime.TotalMilliseconds;

            if (totalTime < LastFire + FireCooldownTime)
            {
                return;
            }

            Vector3    position         = body.Pose.Position.ToVector3();
            Quaternion rotation         = body.Pose.Orientation.ToQuaternion();
            Vector3    forward          = PhysicUtils.Forward(rotation);
            Quaternion laserOrientation = PhysicUtils.DirectionsToQuaternion(forward, Vector3.Up);

            World.InstantiateLaser(position, -forward, laserOrientation, Emitter, LaserVolume);
            LastFire = totalTime;
            FireCounter++;
        }
コード例 #11
0
        private void FaceXWing(BodyReference body, GameTime gameTime)
        {
            Vector3    XWingDirection  = World.xwing.Position() - body.Pose.Position.ToVector3();
            Quaternion RotationToXWing = new Quaternion(XWingDirection, 1f);

            RotationToXWing.Normalize();
            Quaternion ActualRotation = body.Pose.Orientation.ToQuaternion();

            ActualRotation.Normalize();
            Quaternion FinalRotation = Quaternion.Slerp(RotationToXWing, ActualRotation, 8 * (float)gameTime.ElapsedGameTime.TotalSeconds);

            body.Pose.Orientation = FinalRotation.ToBEPU();

            Quaternion rotation = body.Pose.Orientation.ToQuaternion();
            Vector3    forward  = PhysicUtils.Forward(rotation);

            body.Velocity.Linear = (forward * StandarVelocity).ToBEPU();
        }
コード例 #12
0
        private void Flee(BodyReference body, GameTime gameTime)
        {
            Quaternion DegreeRotation = new Quaternion(new Vector3(0, 1, 0), 1f);

            DegreeRotation.Normalize();
            Quaternion ActualRotation = body.Pose.Orientation.ToQuaternion();

            ActualRotation.Normalize();

            Quaternion FinalRotation = Quaternion.Slerp(DegreeRotation, ActualRotation, (float)gameTime.ElapsedGameTime.TotalSeconds);

            body.Pose.Orientation = FinalRotation.ToBEPU();

            Quaternion rotation = body.Pose.Orientation.ToQuaternion();
            Vector3    forward  = PhysicUtils.Forward(rotation);

            body.Velocity.Linear = (forward * FastVelocity).ToBEPU();
        }
コード例 #13
0
    public void UpdatePosition(Vector3 hitPos, Vector3 returnVelocity)
    {
        Vector3 VFBall = returnVelocity;

        Vector3 FPos = hitPos;


        PhysicUtils.LookAheadVelocity_BeforeFloorBounce(ref VFBall, ref FPos);


        float Height = FPos.y;

        float tF = (VFBall.y + Mathf.Sqrt(VFBall.y * VFBall.y + 2 * Constants.G * Height)) / Constants.G;

        float BounceX = FPos.x + VFBall.x * tF;
        float BounceZ = FPos.z + VFBall.z * tF;

        transform.position = new Vector3(BounceX, 0.1f, BounceZ);
    }
コード例 #14
0
        internal void SecondaryFire(double gameTime, Vector2 mousePosition)
        {
            if (gameTime < lastFire + fireCooldownTime)
            {
                return;
            }

            BodyReference body = Body();

            Vector3    position         = body.Pose.Position.ToVector3();
            Quaternion laserOrientation = PhysicUtils.DirectionsToQuaternion(TGCGame.camera.MouseDirection(position), upDirection);
            Vector3    up   = PhysicUtils.Up(laserOrientation);
            Vector3    left = PhysicUtils.Left(laserOrientation);

            World.InstantiateLaser(position + up * 1.0f + left * 4.75459f, -forward, laserOrientation, emitter, laserVolume / 4);
            World.InstantiateLaser(position + up * 1.0f - left * 4.75459f, -forward, laserOrientation, emitter, laserVolume / 4);
            World.InstantiateLaser(position - up * 1.7f + left * 4.75459f, -forward, laserOrientation, emitter, laserVolume / 4);
            World.InstantiateLaser(position - up * 1.7f - left * 4.75459f, -forward, laserOrientation, emitter, laserVolume / 4);

            lastFire = gameTime;
        }
コード例 #15
0
        protected override void OnInstantiate()
        {
            BodyReference body = Body();

            body.Velocity.Linear = -PhysicUtils.Forward(body.Pose.Orientation.ToQuaternion()).ToBEPU() * LinearVelocity;
        }
コード例 #16
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            NativeArray <float3> rayShereDirections   = this.raySphereDirections;
            NativeArray <float3> proxyShereDirections = this.proxySphereDirections;
            int   rayNumOfDirections   = this.rayNumOfDirections;
            int   proxyNumOfDirections = this.proxyNumOfDirections;
            float rayForceStrenght     = Settings.Instance.Boid.Forces.wallRayAvoidForceStrength;
            float proxyForceStrenght   = Settings.Instance.Boid.Forces.wallProximityAvoidForceStrength;
            uint  mask               = Settings.Instance.Boid.ObstacleAvoidance.boidObstacleMask;
            float rayAvoidDistance   = Settings.Instance.Boid.ObstacleAvoidance.rayAvoidDistance;
            float proxyAvoidDistance = Settings.Instance.Boid.ObstacleAvoidance.proxymityAvoidDistance;

            BuildPhysicsWorld physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <BuildPhysicsWorld>();
            PhysicsWorld      physicsWorld       = physicsWorldSystem.PhysicsWorld;

            //inputDeps = JobHandle.CombineDependencies(inputDeps, World.GetOrCreateSystem<EndFramePhysicsSystem>().GetOutputDependency());

            inputDeps = Entities.WithAny <BoidComponent>().ForEach((ref ForceComponent forceComponent, in Translation translation, in LocalToWorld localToWorld) =>
            {
                if (PhysicUtils.Raycast(translation.Value, translation.Value + localToWorld.Up * rayAvoidDistance * 0.8f, mask, 2, physicsWorld)) // Ray avoidance system
                {
                    float3 forceRay = default;
                    float sqrClosestRayHitDistance = float.MaxValue;
                    float bestHitAngle             = float.MaxValue;
                    float3 bestDir = localToWorld.Up;
                    bool hitGot    = false;
                    for (int i = 0; i < rayNumOfDirections; i++)
                    {
                        float3 currenetDir = math.rotate(localToWorld.Value, rayShereDirections[i]);
                        float currentAngle = 1f - math.dot(currenetDir, localToWorld.Up);
                        if (currentAngle + 0.0001f > bestHitAngle)
                        {
                            continue;
                        }

                        bool hit = PhysicUtils.Raycast(translation.Value, translation.Value + currenetDir * rayAvoidDistance, mask, 2, physicsWorld, out RaycastHit raycastHit);
                        if (!hit)
                        {
                            bestHitAngle = currentAngle;
                            bestDir      = currenetDir;
                        }
                        else
                        {
                            float sqrHitDistance = math.lengthsq(translation.Value - raycastHit.Position);
                            if (sqrClosestRayHitDistance > sqrHitDistance)
                            {
                                sqrClosestRayHitDistance = sqrHitDistance;
                            }
                            hitGot = true;
                        }
                    }
                    if (hitGot)
                    {
                        forceRay = Utils.SteerTowards(localToWorld.Up, translation.Value + bestDir * rayForceStrenght * Utils.KernelFunction(sqrClosestRayHitDistance / (rayAvoidDistance * rayAvoidDistance), 1));

                        forceComponent.Force += forceRay;
                    }
                }

                float3 force = default;

                float sqrProxyAvoidDistance = proxyAvoidDistance * proxyAvoidDistance;
                for (int i = 0; i < proxyNumOfDirections; i++)
                {
                    float3 currenetDir = math.rotate(localToWorld.Value, proxyShereDirections[i]);

                    bool hit = PhysicUtils.Raycast(translation.Value, translation.Value + currenetDir * proxyAvoidDistance, mask, 2, physicsWorld, out RaycastHit raycastHit);

                    if (hit)
                    {
                        float sqrHitDistance = math.lengthsq(translation.Value - raycastHit.Position);

                        if (sqrHitDistance > sqrProxyAvoidDistance)
                        {
                            continue;    // Raycast is not 100% accurate, sometimes it finds hits outsice of given radius, we just ignore them
                        }
                        float pushFactor = Utils.KernelFunction(sqrHitDistance / sqrProxyAvoidDistance, 1);

                        force += pushFactor * -currenetDir;
                    }
                }

                forceComponent.Force += Utils.SteerTowards(localToWorld.Up, force * proxyForceStrenght);
            }).Schedule(inputDeps);