Esempio n. 1
0
        void Update()
        {
            var dt = Time.deltaTime;

            if (useGravity)
            {
                var g = Vector3.down * gravity;
                particles.ForEach(p =>
                {
                    p.position += dt * g;
                });
            }

            simulator.Simulate(iterations, dt);

            var mouse = Input.mousePosition;
            var cam   = Camera.main;
            var world = cam.ScreenToWorldPoint(new Vector3(mouse.x, mouse.y, cam.nearClipPlane + 30f));

            particles[Mathf.FloorToInt(count * 0.5f)].position = control.position = world;

            for (int x = 0; x < count; x++)
            {
                // first row
                // particles[x].position = (Vector3.right * x);
            }

            for (int i = 0, n = particles.Count; i < n; i++)
            {
                debuggers[i].transform.position = particles[i].position;
            }
        }
Esempio n. 2
0
        void Update()
        {
            var dt = Time.deltaTime;

            if (useGravity)
            {
                var g = Vector3.down * gravity;
                particles.ForEach(p =>
                {
                    p.position += dt * g;
                });
            }

            simulator.Simulate(iterations, dt);

            var mouse = Input.mousePosition;
            var cam   = Camera.main;
            var world = cam.ScreenToWorldPoint(new Vector3(mouse.x, mouse.y, cam.nearClipPlane + 20f));

            particles[0].position = control.position = world;

            for (int i = 0, n = particles.Count; i < n; i++)
            {
                debuggers[i].transform.position = particles[i].position;
            }
        }
Esempio n. 3
0
    private void MoveActive()
    {
        var dt = Time.deltaTime;

        foreach (var p in particles)
        {
            if (useGravity)
            {
                var g = Vector3.down * gravity;

                p.position += dt * g;
            }
        }

        simulator.Simulate(iterations, dt);
        if (isDead)
        {
            particles.ForEach(p => p.LockToJoint());
        }
        else
        {
            particles.ForEach(p => p.AdjusTLockedPosition());
        }
        if (activeJoint != 5)
        {
            particles[activeJoint].position = Joints[activeJoint].transform.position = GetWorld();
        }

        for (int n = 0; n < particles.Count; n++)
        {
            Joints[n].transform.position = particles[n].position;
        }
    }
Esempio n. 4
0
        public void Update(DynamicUpdateState gameTime)
        {
            var elapsedS = (float)gameTime.RealTime.TotalSeconds;

            Vector3D newPos;

            VerletSimulator.Simulate(elapsedS, out newPos);
            Npc.DynamicEntity.Position = newPos;

            VerletSimulator.CurPosition = Npc.DynamicEntity.Position;

            if (IsMoving)
            {
                if (Vector3D.DistanceSquared(_pathTargetPoint, Npc.DynamicEntity.Position) < 0.1d)
                {
                    FollowNextPoint();
                }

                _moveDirection = _pathTargetPoint - Npc.DynamicEntity.Position;

                _jump            = _moveDirection.Y > 0;
                _moveDirection.Y = 0;

                //if (Vector3D.DistanceSquared(VerletSimulator.PrevPosition, VerletSimulator.CurPosition) < 0.01f)
                //{
                //    if (Math.Abs(_moveDirection.X) < Math.Abs(_moveDirection.Z))
                //        _moveDirection.Z = 0.1f * Math.Sign(_moveDirection.Z);
                //    else
                //        _moveDirection.X = 0.1f * Math.Sign(_moveDirection.X);
                //}

                _moveDirection.Normalize();

                VerletSimulator.Impulses.Add(new Impulse(elapsedS)
                {
                    ForceApplied = _moveDirection.AsVector3() * Npc.DynamicEntity.MoveSpeed * (_runAway ? 2f : 1f)
                });

                if (_jump && VerletSimulator.OnGround)
                {
                    VerletSimulator.Impulses.Add(new Impulse(elapsedS)
                    {
                        ForceApplied = Vector3.UnitY * 22
                    });
                }
            }

            if (_leader != null && Vector3D.Distance(_leader.Position, Npc.DynamicEntity.Position) > FollowStayDistance)
            {
                if (IsMoving && Vector3D.Distance(new Vector3D(_path.Goal) + CubeCenter, _leader.Position) < FollowStayDistance)
                {
                    return;
                }

                MoveTo(_leader.Position.ToCubePosition());
            }
        }