コード例 #1
0
    void HandleMovement()
    {
        float xAxis = Input.GetAxisRaw("Horizontal");
        float yAxis = Input.GetAxisRaw("Vertical");

        // Stop the player from moving if no input is active
        if (Mathf.Abs(xAxis) < float.Epsilon && Mathf.Abs(yAxis) < float.Epsilon)
        {
            physics.AddForce(Vector2.zero);
            shouldIdle = true;
            SoundManager.StopSoundLooping(footstepSoundHandle);
            events.FireEvent(new PlayerStopMoving());
            return;
        }
        var movementVector = new Vector2(xAxis, yAxis).normalized;

        float adjustedSpeed = stats.MoveSpeed; //- gunObject.GetComponent<GunController>().stats.Weight.ModdedValue();

        var vel = movementVector * adjustedSpeed;

        if (shouldIdle)
        {
            footstepSoundHandle = SoundManager.PlaySoundLooping(Sounds.PlayerFootsteps);
            events.FireEvent(new PlayerStartMoving());
        }
        physics.AddForce(vel);
        shouldIdle = false;
    }
コード例 #2
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            // DA: Consider using havok fields (buoyancy demo) for gravity of planets.
            Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPointForGrid(PositionComp.GetPosition());

            Physics.AddForce(Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, Physics.Mass * gravity, Physics.CenterOfMassWorld, null);
        }
コード例 #3
0
 void ApplyForce()
 {
     if (physics == null)
     {
         physics = GetComponent <Physics>();
     }
     physics.AddForce(forceToApply);
     Invoke("StopForce", durationOfForce);
 }
コード例 #4
0
ファイル: DasherTasks.cs プロジェクト: scottbass47/gsts
    public void Dash()
    {
        float dashTime  = dasherStats.DashTime;
        float dashSpeed = dasherStats.DashDistance / dashTime;

        var task = Task.current;

        if (task.isStarting)
        {
            task.item = new WaitTime {
                Elapsed = 0, Duration = dashTime
            };
        }
        var info = task.item as WaitTime;

        info.Elapsed += Time.deltaTime;
        physics.AddForce(dashDir * dashSpeed);

        if (info.Elapsed > info.Duration)
        {
            task.Succeed();
        }
    }
コード例 #5
0
    // Update is a Unity function that is called every frame.  This is basically just the game loop.
    private void Update()
    {
        // Thrust controls
        if (Input.GetButton("Forward"))
        {
            Vector2 forwardVector = currentRotation.GetVector();
            phys.AddForce(thrustForce * forwardVector);
        }
        else if (Input.GetButton("Reverse"))
        {
            Vector2 forwardVector = currentRotation.GetVector();
            phys.AddForce(-1 * thrustForce * forwardVector);
        }

        // Boost controls
        if (Input.GetButtonDown("Boost"))
        {
            Vector2 forwardVector = currentRotation.GetVector();
            phys.AddForce(boostForce * forwardVector);
        }

        // Turn controls
        if (Input.GetButton("TurnLeft"))
        {
            currentRotation.AddAngle(turnSpeed);
            transform.eulerAngles = new Vector3(0, 0, currentRotation.GetDegrees());
        }
        else if (Input.GetButton("TurnRight"))
        {
            currentRotation.AddAngle(-turnSpeed);
            transform.eulerAngles = new Vector3(0, 0, currentRotation.GetDegrees());
        }

        if (!bounds.Contains(transform.position))
        {
            Bounce();
        }
    }
コード例 #6
0
 public override void OnUpdate()
 {
     knockbackHandler.Update();
     targetPhysics.AddForce(knockbackHandler.GetKnockbackForce());
 }
コード例 #7
0
            public override void Update(GameTime gt)
            {
                base.Update(gt);

                if (!HasFocus && Body.BoundingRect.Contains((int)MouseService.Cursor.Position.X,
                                                            (int)MouseService.Cursor.Position.Y))
                {
                    _imageRender.Color = HoverColor;
                    if (MouseService.IsMouseButtonPressed(MouseButton.LeftButton))
                    {
                        _clickposition = MouseService.Cursor.Position;
                        HasFocus       = true;
                    }
                    if (MouseService.IsMouseButtonPressed(MouseButton.RightButton))
                    {
                        HasFocus       = true;
                        _lastImmovable = Collision.Immovable;
                    }
                }
                else if (!HasFocus)
                {
                    //_clickposition = Vector2.Zero;
                    //_releaseposition = Vector2.Zero;
                    _imageRender.Color = Color;
                }

                if (HasFocus && MouseService.IsMouseButtonReleased(MouseButton.LeftButton))
                {
                    HasFocus         = false;
                    _releaseposition = MouseService.Cursor.Position;

                    //Add delta to force.
                    _physics.AddForce((_clickposition - _releaseposition) / 2f);
                }
                else if (HasFocus && MouseService.IsMouseButtonDown(MouseButton.RightButton))
                {
                    Body.Position      -= new Vector2(MouseService.Delta.X, MouseService.Delta.Y);
                    Collision.Immovable = true;
                }
                else if (HasFocus && MouseService.IsMouseButtonUp(MouseButton.LeftButton) && MouseService.IsMouseButtonUp(MouseButton.RightButton))
                {
                    HasFocus            = false;
                    Collision.Immovable = _lastImmovable;
                }

                //ResetTimer our position if it goes off screen.
                if (Body.Right < 0)
                {
                    Body.X = EntityGame.Viewport.Width;
                }
                else if (Body.Left > EntityGame.Viewport.Width)
                {
                    Body.X = 0 - Body.Width;
                }

                if (Body.Bottom < 0)
                {
                    Body.Y = EntityGame.Viewport.Height;
                }
                else if (Body.Top > EntityGame.Viewport.Height)
                {
                    Body.Y = 0 - Body.Bounds.Y;
                }

                _textRender.Text = Name + Environment.NewLine +
                                   "X:" + Math.Round(Body.X, 2) + Environment.NewLine +
                                   "Y" + Math.Round(Body.Y, 2);
                _textBody.Position = Body.Position + Vector2.One * 3;
            }