コード例 #1
0
    void Update()
    {
        RaycastHit hit;
        Ray        forward  = new Ray(transform.position, transform.forward);
        Ray        backward = new Ray(transform.position, transform.forward * -1);

        if (Physics.Raycast(forward, out hit) || Physics.Raycast(backward, out hit))
        {
            if (hit.transform.CompareTag("Enemy"))
            {
                direction *= -1;
            }
            else if (hit.transform.gameObject.CompareTag("Player") && !isCoolingDown)
            {
                isCoolingDown = true;
                FireComponent.numberOfCollectedParasites = 1;
                FireComponent.Fire();

                Invoke("ResetCoolDown", 2 / difficultyMultipyer);
            }
            else if (hit.distance < 1.1f && Physics.Raycast(transform.position + Vector3.up * 0.2f, -transform.up, 0.25f))
            {
                //JumpComponent.Jump();
            }
        }

        MovmentComponent.Move(direction);

        RotationComponent.RotateTowards(target);
        MovmentComponent.thisUpdate();
    }
コード例 #2
0
 private void Awake()
 {
     selfTrans    = transform;
     MovementComp = GetComponent <MovementComponent>();
     RotationComp = GetComponent <RotationComponent>();
     onAwake();
 }
コード例 #3
0
 public override void Update(float dt)
 {
     foreach (Entity rotationEntity in _rotationEntities)
     {
         RotationComponent rotationComp = rotationEntity.GetComponent <RotationComponent>();
         rotationEntity.GetComponent <TransformComponent>().Rotate(rotationComp.RotationSpeed * dt);
     }
 }
コード例 #4
0
ファイル: TargetSystem.cs プロジェクト: SamEmam/SBS_Bachelor
 // Set new target if score of other ship is higher than current target
 void UpdateTarget(int enemyScore, int targetScore, RotationComponent rotationC, Transform target)
 {
     if (enemyScore >= targetScore)
     {
         targetScore      = enemyScore;
         rotationC.target = target;
     }
 }
コード例 #5
0
        public override void Process(Entity entity)
        {
            RotationComponent rc = entity.GetComponent <RotationComponent>();

            if (rc.AutoRotate)
            {
                rc.Angle = MathFunctions.ClampAngle(rc.Angle + rc.RotationSpeed);
            }
        }
コード例 #6
0
ファイル: EntitiesManager.cs プロジェクト: soulhez/LearnUnity
    /// <summary>
    /// 把GameObject转为 实体(Entity)
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="dstManager"></param>
    /// <param name="conversionSystem"></param>
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        /// 创建一个组件
        RotationComponent data = new RotationComponent {
            Speed = Speed
        };

        // 把  组件 加入EntityManager 中,让Untiy 内置的环境实体管理器 管理
        dstManager.AddComponentData(entity, data);
    }
コード例 #7
0
    //TODO Can I return RotationComponent?
    public static (float x, float y) CalculateAddedRotation(this RotationComponent currentRotation, float addingDegree)
    {
        var rad = (float)(Math.PI / 180F) * addingDegree;
        var cos = (float)Math.Cos(rad);
        var sin = (float)Math.Sin(rad);

        var rotationX = currentRotation.x * cos - currentRotation.y * sin;
        var rotationY = currentRotation.y * cos + currentRotation.x * sin;

        return(rotationX, rotationY);
    }
コード例 #8
0
ファイル: SurfLevel.cs プロジェクト: abowen/MonoGameOpenGL
        private GameObject CreatePlayer(int playerNumber, Color color)
        {
            // MonoGame works in Radians
            // http://msdn.microsoft.com/en-us/library/system.math.sin%28v=vs.110%29.aspx
            var startX        = GameHelper.GetRelativeScaleX(0.1f);
            var startLocation = new Vector2(startX, _waveTopY) + new Vector2(playerNumber * startX, 0);
            var startRotation = (float)(90 * (Math.PI / 180));

            var texture            = SurfingGraphics.Surfboard_Large_White_Asset;
            var player             = new GameObject("Player", startLocation, startRotation);
            var airGravityMovement = new AccelerateMovementComponent(new Vector2(0, 0.05f));
            var outOfBoundary      = new OutOfBoundsComponent(ObjectEvent.ResetEntity);
            var boundary           = new BoundaryComponent(texture, texture.Width, texture.Height);
            var rotationMovement   = new RotationMovementComponent(2, Vector2.Zero);
            var rotation           = new RotationComponent(Vector2.Zero);
            var sprite             = new SpriteComponent(texture, rotationOrigin: texture.Centre(), color: color);

            player.AddComponent(airGravityMovement);
            player.AddComponent(sprite);
            player.AddComponent(rotationMovement);
            player.AddComponent(boundary);
            player.AddComponent(outOfBoundary);
            player.AddComponent(rotation);

            var onWave = "OnWave";
            var inAir  = "InAir";

            var state = new StateStringComponent();

            state.AddComponentState(rotationMovement, onWave, inAir);
            state.AddComponentState(rotation, inAir, onWave);
            state.AddComponentState(airGravityMovement, inAir, onWave);

            player.AddComponent(state);

            var boundaryState = new BoundaryStateComponent(new Rectangle(0, _waveTopY, GameHelper.GetRelativeScaleX(1f), (int)(_waveHeight * 1.3f)), onWave, inAir);

            player.AddComponent(boundaryState);

            ForegroundLayer.AddGameObject(player);

            return(player);
        }
コード例 #9
0
        void OnDrawGizmosSelected()
        {
            AISpawnBoltData spawnData = Value;

            Gizmos.color = Color.blue;
            Vector3 position = new Vector3(spawnData.spawnPosition.x,
                                           spawnData.spawnPosition.y,
                                           spawnData.spawnPosition.z);

            RotationComponent rotationComponent = GetComponent <RotationComponent>();

            if (rotationComponent)
            {
                Vector3 forward = math.forward(rotationComponent.Value.Value);
                position += forward * spawnData.offset;
            }

            Gizmos.DrawSphere(position, 0.1f);
        }
コード例 #10
0
        public override void Process(Entity entity)
        {
            ThrustComponent   tc = entity.GetComponent <ThrustComponent>();
            RotationComponent rc = entity.GetComponent <RotationComponent>();

            if (InputManager.Instance.isKeyReleased(Keys.Space))
            {
                PositionComponent pc    = entity.GetComponent <PositionComponent>();
                InertiaComponent  ic    = entity.GetComponent <InertiaComponent>();
                Entity            laser = this.EntityWorld.CreateEntity();

                laser.AddComponent(new ProjectileComponent(15, new TimeSpan(0, 0, 0, 0, 450)));
                laser.AddComponent(new PositionComponent(pc.Position));
                laser.AddComponent(new RotationComponent(rc.Angle, 0f, false));
                float radians = MathHelper.ToRadians(rc.Angle);
                laser.AddComponent(new InertiaComponent(Vector2.Multiply(Vector2.Normalize(new Vector2((float)Math.Sin(radians), -(float)Math.Cos(radians))), laser.GetComponent <ProjectileComponent>().MaxSpeed)));
                laser.AddComponent(new TextureComponent(new Coord(0, 0), "lasers", new Vector2(0, 0)));
            }
        }
コード例 #11
0
        public override void Process(Entity entity)
        {
            TextureComponent  tc = entity.GetComponent <TextureComponent>();
            PositionComponent pc = entity.GetComponent <PositionComponent>();
            RotationComponent rc = (entity.HasComponent <RotationComponent>()) ? entity.GetComponent <RotationComponent>() : new RotationComponent(0, 0, false);
            ShadowComponent   sc = (entity.HasComponent <ShadowComponent>()) ? entity.GetComponent <ShadowComponent>() : null;

            Rectangle sourceRect = ResourceManager.Instance.GetSpriteSheet(tc.Texture).GetSourceRect(tc.Position.X, tc.Position.Y);
            Rectangle destRect   = new Rectangle((int)pc.Position.X, (int)pc.Position.Y, sourceRect.Width, sourceRect.Height);
            Texture2D texture    = ResourceManager.Instance.GetSpriteSheet(tc.Texture).Texture;

            ScreenManager.Instance.SpriteBatch.Draw(texture, destRect, sourceRect, Color.White, MathHelper.ToRadians(rc.Angle), tc.Origin, SpriteEffects.None, 0f);

            //if (sc != null)
            //{
            //    Rectangle shadowSourceRect = ResourceManager.Instance.GetSpriteSheet(sc.Texture).GetSourceRect(sc.Position.X, sc.Position.Y);
            //    Texture2D shadowTexture = ResourceManager.Instance.GetSpriteSheet(sc.Texture).Texture;
            //    ScreenManager.Instance.SpriteBatch.Draw(shadowTexture, destRect, shadowSourceRect, Color.White, sc.Angle, sc.Origin, SpriteEffects.None, 0f);
            //}
        }
コード例 #12
0
ファイル: Camera.cs プロジェクト: Metapyziks/OpenTKTK
 private void OnRotationChanged(RotationComponent component)
 {
     OnRotationChanged(component, ref _rotation);
 }
コード例 #13
0
 public override void Process(Entity entity)
 {
     CollisionComponent cc = entity.GetComponent <CollisionComponent>();
     PositionComponent  pc = entity.GetComponent <PositionComponent>();
     RotationComponent  rc = (entity.HasComponent <RotationComponent>()) ? entity.GetComponent <RotationComponent>() : new RotationComponent(0, 0, false);
 }
コード例 #14
0
        public override void Process(Entity entity)
        {
            ThrustComponent tc = entity.GetComponent <ThrustComponent>();

            if (tc.ForwardThrust)
            {
                InertiaComponent  ic = entity.GetComponent <InertiaComponent>();
                RotationComponent rc = entity.GetComponent <RotationComponent>();

                double angleInDegrees = MathHelper.ToRadians(rc.Angle);
                ic.Inertia.X += (float)Math.Sin(angleInDegrees) * tc.Acceleration;
                ic.Inertia.Y += -(float)Math.Cos(angleInDegrees) * tc.Acceleration;

                if (ic.Inertia.Length() > tc.MaxSpeed)
                {
                    ic.Inertia.Normalize();
                    ic.Inertia = Vector2.Multiply(ic.Inertia, tc.MaxSpeed);
                }
            }

            if (tc.BackwardThrust)
            {
                InertiaComponent  ic = entity.GetComponent <InertiaComponent>();
                RotationComponent rc = entity.GetComponent <RotationComponent>();

                float currentSpeed = ic.Inertia.Length();

                ic.Inertia = Vector2.Multiply(ic.Inertia, tc.Deceleration);

                if (ic.Inertia.Length() < tc.Acceleration)
                {
                    ic.Inertia.X = 0;
                    ic.Inertia.Y = 0;
                }
            }

            if (tc.LeftThrust)
            {
                InertiaComponent  ic = entity.GetComponent <InertiaComponent>();
                RotationComponent rc = entity.GetComponent <RotationComponent>();

                double angleInDegrees = MathHelper.ToRadians(rc.Angle - 90); // 90 degrees anti-clockwise
                ic.Inertia.X += (float)Math.Sin(angleInDegrees) * 0.05f;
                ic.Inertia.Y += -(float)Math.Cos(angleInDegrees) * 0.05f;

                if (ic.Inertia.Length() > tc.MaxSpeed)
                {
                    ic.Inertia.Normalize();
                    ic.Inertia = Vector2.Multiply(ic.Inertia, tc.MaxSpeed);
                }
            }

            if (tc.RightThrust)
            {
                InertiaComponent  ic = entity.GetComponent <InertiaComponent>();
                RotationComponent rc = entity.GetComponent <RotationComponent>();

                double angleInDegrees = MathHelper.ToRadians(rc.Angle + 90); // 90 degrees clockwise
                ic.Inertia.X += (float)Math.Sin(angleInDegrees) * 0.05f;
                ic.Inertia.Y += -(float)Math.Cos(angleInDegrees) * 0.05f;

                if (ic.Inertia.Length() > tc.MaxSpeed)
                {
                    ic.Inertia.Normalize();
                    ic.Inertia = Vector2.Multiply(ic.Inertia, tc.MaxSpeed);
                }
            }
        }
コード例 #15
0
ファイル: OrthoCamera.cs プロジェクト: alexturpin/Zombles
 protected override void OnRotationChanged(RotationComponent component, ref Vector2 rotation)
 {
     if (component.HasFlag(RotationComponent.Pitch)) {
         InvalidateProjectionMatrix();
     } else {
         base.OnRotationChanged(component, ref rotation);
     }
 }
コード例 #16
0
ファイル: Camera.cs プロジェクト: alexturpin/Zombles
 /// <summary>
 /// Method called when the camera's rotation has been modified.
 /// </summary>
 /// <param name="component">The component(s) of the camera's rotation
 /// that were modified</param>
 protected virtual void OnRotationChanged(RotationComponent component, ref Vector2 rotation)
 {
     InvalidateViewMatrix();
 }
コード例 #17
0
ファイル: Camera.cs プロジェクト: alexturpin/Zombles
 private void OnRotationChanged(RotationComponent component)
 {
     OnRotationChanged(component, ref _rotation);
 }
コード例 #18
0
ファイル: ModelSwitcher.cs プロジェクト: Flafla2/Rotation-Vis
    public void UpdateRotation(string valueStr, bool start, RotationComponent component)
    {
        RotationUI ui       = start ? _StartRotUI : _EndRotUI;
        Quaternion rotation = start ? _StartRot : _EndRot;
        var        ea       = rotation.eulerAngles;
        float      value;

        if (!float.TryParse(valueStr, out value))
        {
            return;
        }

        switch (component)
        {
        case RotationComponent.EulerX:
            ea.x = value;
            rotation.eulerAngles = ea;
            SetQuatFields(rotation, ui);
            break;

        case RotationComponent.EulerY:
            ea.y = value;
            rotation.eulerAngles = ea;
            SetQuatFields(rotation, ui);
            break;

        case RotationComponent.EulerZ:
            ea.z = value;
            rotation.eulerAngles = ea;
            SetQuatFields(rotation, ui);
            break;

        case RotationComponent.QuatX:
            rotation.x = value;
            SetEulerFields(rotation, ui);
            break;

        case RotationComponent.QuatY:
            rotation.y = value;
            SetEulerFields(rotation, ui);
            break;

        case RotationComponent.QuatZ:
            rotation.z = value;
            SetEulerFields(rotation, ui);
            break;

        case RotationComponent.QuatW:
            rotation.w = value;
            SetEulerFields(rotation, ui);
            break;
        }

        if (start)
        {
            _StartRot = rotation;
        }
        else
        {
            _EndRot = rotation;
        }

        ApplyInterpolation(_InterpSlider.value);
    }
コード例 #19
0
ファイル: AimComponent.cs プロジェクト: SamEmam/SBS_Bachelor
 private void Start()
 {
     parentRotationComponent = gameObject.GetComponentInParent <RotationComponent>();
 }
コード例 #20
0
        public override void Process(Entity entity)
        {
            NavigationComponent nc = entity.GetComponent <NavigationComponent>();

            if (nc.TargetLocation.HasValue)
            {
                PositionComponent pc               = entity.GetComponent <PositionComponent>();
                float             deltaX           = pc.Position.X - nc.TargetLocation.Value.X;
                float             deltaY           = pc.Position.Y - nc.TargetLocation.Value.Y;
                float             distanceToTarget = (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));

                if (distanceToTarget < 15)
                {
                    nc.TargetLocation = null;
                    entity.GetComponent <ThrustComponent>().ForwardThrust  = false;
                    entity.GetComponent <ThrustComponent>().BackwardThrust = true;
                    return;
                }

                float angle        = (float)Math.Atan2((nc.TargetLocation.Value.Y - pc.Position.Y), (nc.TargetLocation.Value.X - pc.Position.X)) + MathHelper.PiOver2;
                float angleDegrees = MathHelper.ToDegrees(angle);
                if (angleDegrees < 0)
                {
                    angleDegrees += 360;
                }

                RotationComponent rc = entity.GetComponent <RotationComponent>();

                float angleDiff = angleDegrees - rc.Angle;

                if (angleDiff > 180)
                {
                    angleDiff -= 360;
                }
                if (angleDiff < -180)
                {
                    angleDiff += 360;
                }

                if (angleDiff < -rc.RotationSpeed)
                {
                    entity.GetComponent <ThrustComponent>().ForwardThrust  = false;
                    entity.GetComponent <ThrustComponent>().BackwardThrust = true;
                    rc.Angle -= rc.RotationSpeed;
                    if (rc.Angle < 0)
                    {
                        rc.Angle += 360;
                    }
                }
                else if (angleDiff > rc.RotationSpeed)
                {
                    entity.GetComponent <ThrustComponent>().ForwardThrust  = false;
                    entity.GetComponent <ThrustComponent>().BackwardThrust = true;
                    rc.Angle += rc.RotationSpeed;
                    if (rc.Angle > 360)
                    {
                        rc.Angle -= 360;
                    }
                }
                else
                {
                    ThrustComponent  tc = entity.GetComponent <ThrustComponent>();
                    InertiaComponent ic = entity.GetComponent <InertiaComponent>();

                    float ticksToTarget = distanceToTarget / ic.Inertia.Length();
                    float ticksToStop   = (float)Math.Log(ic.Inertia.Length() / tc.Deceleration) / tc.Deceleration;

                    if (ticksToTarget > ticksToStop + 15)
                    {
                        tc.ForwardThrust  = true;
                        tc.BackwardThrust = false;
                    }
                    else
                    {
                        tc.ForwardThrust  = false;
                        tc.BackwardThrust = true;
                    }
                }
            }
            else
            {
                if (entity.GetComponent <InertiaComponent>().Inertia.Length() == 0)
                {
                    entity.GetComponent <ThrustComponent>().ForwardThrust  = false;
                    entity.GetComponent <ThrustComponent>().BackwardThrust = false;
                }
            }
        }
コード例 #21
0
    void DistanceToWaypointCheck(Transform waypoint, Transform spaceship, int maxDistance, RotationComponent rotationC, bool closeEnoughToWaypoint)
    {
        var dist = Vector3.Distance(waypoint.position, spaceship.position);     // Calculate distance between ship and waypoint

        if (dist > maxDistance)                                                 // If distance is larger than max distance
        {
            rotationC.target      = waypoint;                                   // Set target to waypoint and set isCloseEnoughToWaypoint boolean
            closeEnoughToWaypoint = false;
        }
        else
        {
            closeEnoughToWaypoint = true;                                       // Else set isCloseEnoughToWaypoint boolean
        }
    }
コード例 #22
0
ファイル: Camera.cs プロジェクト: Metapyziks/OpenTKTK
 /// <summary>
 /// Method called when the camera's rotation has been modified.
 /// </summary>
 /// <param name="component">The component(s) of the camera's rotation
 /// that were modified</param>
 protected virtual void OnRotationChanged(RotationComponent component, ref Vector2 rotation)
 {
     InvalidateViewMatrix();
 }