public virtual void PlayerMoveRequest(SceneNode sceneNode, Vector3 desiredDisplacement, ref Vector3 pos, bool followTerrain, float timeSinceLastFrame, ref bool dirty) { if (playerController == null) { return; } desiredDisplacement = desiredDisplacement / scaleFactor; IndexedVector3 indexedDisplacement = new IndexedVector3(desiredDisplacement); playerController.SetWalkDirection(ref indexedDisplacement); m_dynamicsWorld.StepSimulation(timeSinceLastFrame / 1000, 3); //log.Info("BULLET: completed step simulation"); UpdateMobPositions(); TryAddObjects(); // Get the players current position IndexedMatrix worldTransform = playerController.GetGhostObject().GetWorldTransform(); pos = new Vector3(worldTransform.ToMatrix().M41, worldTransform.ToMatrix().M42, worldTransform.ToMatrix().M43); //pos.y -= playerController.Height / 2; //pos.y -= playerController.Radius; if (pos.Y < 0) { pos.Y = 0; IndexedVector3 indexedPosition = new IndexedVector3(pos); playerController.Warp(ref indexedPosition); } pos = pos * scaleFactor; }
protected void Walk(OpenTK.Mathematics.Vector3 dir, float frameDelta) { if (_charController.OnGround) { var mat = Node.GetTransform.GlobalTransform; mat.ClearTranslation(); var direction = (new OpenTK.Mathematics.Vector4(-dir) * mat).Xyz.Convert(); //var direction = new Vector3(mat.M31, 0, mat.M33); //direction.Normalize(); _charController.SetWalkDirection(-direction * frameDelta * WalkSpeed); } }
public override void OnHandleInput() { Matrix transform = _ghostObject.WorldTransform; Vector3 forwardDir = new Vector3(transform.M31, transform.M32, transform.M33); forwardDir.Normalize(); //Console.WriteLine("forwardDir={0}", forwardDir); Vector3 upDir = new Vector3(transform.M21, transform.M22, transform.M23); upDir.Normalize(); Vector3 walkDirection = Vector3.Zero; const float walkVelocity = 1.1f * 4.0f; float walkSpeed = walkVelocity * FrameDelta * 10;// * 0.0001f; float turnSpeed = FrameDelta * 3; Vector3 position = transform.Origin; if (Input.KeysDown.Contains(Keys.Left)) { transform.Origin = Vector3.Zero; transform *= Matrix.RotationAxis(upDir, -turnSpeed); transform.Origin = position; _ghostObject.WorldTransform = transform; } if (Input.KeysDown.Contains(Keys.Right)) { transform.Origin = Vector3.Zero; transform *= Matrix.RotationAxis(upDir, turnSpeed); transform.Origin = position; _ghostObject.WorldTransform = transform; } if (Input.KeysDown.Contains(Keys.Up)) { walkDirection += forwardDir; } if (Input.KeysDown.Contains(Keys.Down)) { walkDirection -= forwardDir; } Vector3 cameraPos = position - forwardDir * 12 + upDir * 5; //use the convex sweep test to find a safe position for the camera (not blocked by static geometry) _convexResultCallback.ConvexFromWorld = position; _convexResultCallback.ConvexToWorld = cameraPos; _convexResultCallback.ClosestHitFraction = 1.0f; World.ConvexSweepTest(_cameraSphere, Matrix.Translation(position), Matrix.Translation(cameraPos), _convexResultCallback); if (_convexResultCallback.HasHit) { cameraPos = Vector3.Lerp(position, cameraPos, _convexResultCallback.ClosestHitFraction); } Freelook.Eye = cameraPos; Freelook.Target = position; _character.SetWalkDirection(walkDirection * walkSpeed); if (Input.KeysDown.Contains(Keys.Space)) { _character.Jump(); return; } base.OnHandleInput(); }
public override void OnHandleInput() { Matrix xform = ghostObject.WorldTransform; Vector3 forwardDir = new Vector3(xform.M31, xform.M32, xform.M33); //Console.Write("forwardDir={0},{1},{2}\n", forwardDir[0], forwardDir[1], forwardDir[2]); Vector3 upDir = new Vector3(xform.M21, xform.M22, xform.M23); forwardDir.Normalize(); upDir.Normalize(); Vector3 pos = xform.Origin; Vector3 walkDirection = Vector3.Zero; const float walkVelocity = 1.1f * 4.0f; float walkSpeed = walkVelocity * FrameDelta * 10;// * 0.0001f; float turnSpeed = FrameDelta * 3; if (Input.KeysDown.Contains(Keys.Left)) { Matrix orn = xform; orn.Row4 = new Vector4(0, 0, 0, 1); orn *= Matrix.RotationAxis(upDir, -turnSpeed); orn.Row4 = new Vector4(pos.X, pos.Y, pos.Z, 1); ghostObject.WorldTransform = orn; } if (Input.KeysDown.Contains(Keys.Right)) { Matrix orn = xform; orn.Row4 = new Vector4(0, 0, 0, 1); orn *= Matrix.RotationAxis(upDir, turnSpeed); orn.Row4 = new Vector4(pos.X, pos.Y, pos.Z, 1); ghostObject.WorldTransform = orn; } if (Input.KeysDown.Contains(Keys.Up)) { walkDirection += forwardDir; } if (Input.KeysDown.Contains(Keys.Down)) { walkDirection -= forwardDir; } Vector3 cameraPos = pos - forwardDir * 12 + upDir * 5; //use the convex sweep test to find a safe position for the camera (not blocked by static geometry) convexResultCallback.ConvexFromWorld = pos; convexResultCallback.ConvexToWorld = cameraPos; convexResultCallback.ClosestHitFraction = 1.0f; World.ConvexSweepTest(cameraSphere, Matrix.Translation(pos), Matrix.Translation(cameraPos), convexResultCallback); if (convexResultCallback.HasHit) { cameraPos = Vector3.Lerp(pos, cameraPos, convexResultCallback.ClosestHitFraction); } Freelook.SetEyeTarget(cameraPos, pos); character.SetWalkDirection(walkDirection * walkSpeed); if (Input.KeysDown.Contains(Keys.Space)) { character.Jump(); return; } base.OnHandleInput(); }
public override void OnHandleInput() { Matrix xform = ghostObject.WorldTransform; Vector3 forwardDir = new Vector3(xform.M31, xform.M32, xform.M33); //Console.Write("forwardDir={0},{1},{2}\n", forwardDir[0], forwardDir[1], forwardDir[2]); Vector3 upDir = new Vector3(xform.M21, xform.M22, xform.M23); forwardDir.Normalize(); upDir.Normalize(); Vector3 pos = xform.Origin; Vector3 walkDirection = Vector3.Zero; const float walkVelocity = 1.1f * 4.0f; float walkSpeed = walkVelocity * FrameDelta * 10;// * 0.0001f; float turnSpeed = FrameDelta * 3; if (Input.KeysDown.Contains(Keys.Left)) { Matrix orn = xform; orn.Row4 = new Vector4(0, 0, 0, 1); orn *= Matrix.RotationAxis(upDir, -turnSpeed); orn.Row4 = new Vector4(pos.X, pos.Y, pos.Z, 1); ghostObject.WorldTransform = orn; } if (Input.KeysDown.Contains(Keys.Right)) { Matrix orn = xform; orn.Row4 = new Vector4(0, 0, 0, 1); orn *= Matrix.RotationAxis(upDir, turnSpeed); orn.Row4 = new Vector4(pos.X, pos.Y, pos.Z, 1); ghostObject.WorldTransform = orn; } if (Input.KeysDown.Contains(Keys.Up)) { walkDirection += forwardDir; } if (Input.KeysDown.Contains(Keys.Down)) { walkDirection -= forwardDir; } Vector3 cameraPos = pos - forwardDir * 12 + upDir * 5; //use the convex sweep test to find a safe position for the camera (not blocked by static geometry) SphereShape cameraSphere = new SphereShape(0.2f); ClosestConvexResultCallback cb = new ClosestConvexResultCallback(ref pos, ref cameraPos); cb.CollisionFilterMask = (short)CollisionFilterGroups.StaticFilter; Matrix posMatrix = Matrix.Translation(pos); Matrix cameraPosMatrix = Matrix.Translation(cameraPos); World.ConvexSweepTestRef(cameraSphere, ref posMatrix, ref cameraPosMatrix, cb); cameraSphere.Dispose(); if (cb.HasHit) { cameraPos = Vector3.Lerp(pos, cameraPos, cb.ClosestHitFraction); } cb.Dispose(); Freelook.SetEyeTarget(cameraPos, pos); character.SetWalkDirection(walkDirection * walkSpeed); base.OnHandleInput(); }
public void Move(Vector3 displacement) { m_characterController.SetWalkDirection(displacement.ToBullet()); }
public void Move(Vector3 displacement, bool canmove = false) { this.GetParent <Unit>().needSend = canmove; m_characterController.SetWalkDirection(displacement.ToBullet()); }