public static double GetDistance(IMoveableObject objectA, IMoveableObject objectB) { double distanceX = objectA.Position.X - objectB.Position.X; double distanceY = objectA.Position.Y - objectB.Position.Y; double distance = Math.Sqrt(distanceX * distanceX + distanceY * distanceY); return distance; }
private Vector GetResultingVelocityFromCollision(IMoveableObject objectA, IMoveableObject objectB) { double mass = (2 * objectB.Mass) / (objectA.Mass + objectB.Mass); Vector distance = objectA.Position - objectB.Position; double magnitude = Math.Pow(distance.Length, 2); double dotProduct = Vector.Multiply(objectA.Velocity - objectB.Velocity, distance); Vector productTerm2 = Vector.Multiply(mass * dotProduct / magnitude, distance); Vector result = objectA.Velocity - productTerm2; return result; }
public void AddAiPlayer(Vector2 position, IMoveableObject target, float difficulty = 1.0f) { GameObject model = GameObject.Instantiate(PaddleModel, new Vector3(position.x, position.y), Quaternion.identity); AiPlayer player = model.AddComponent <AiPlayer>(); player.SetTarget(target); player.SetSpeed(8.0f); player.SetDifficulty(difficulty); Players.Add(player); }
/// <summary> /// Controleert welke knop er ingedrukt is /// </summary> /// <param name="moveableObject"></param> public override void Update(IMoveableObject moveableObject) { KeyboardState stateKey = Keyboard.GetState(); if (stateKey.IsKeyDown(Keys.T) && TeleportCheat) { moveableObject.ChangePosition(11561, 642); } if (stateKey.IsKeyDown(Keys.Left) && Right == false) { Left = true; moveableObject.ChangeVelocity(-movementSpeed, null); } if (stateKey.IsKeyUp(Keys.Left) && Right == false) { Left = false; moveableObject.ChangeVelocity(0, null); } if (stateKey.IsKeyDown(Keys.Right) && Left == false) { Right = true; moveableObject.ChangeVelocity(movementSpeed, null); } if (stateKey.IsKeyUp(Keys.Right) && Left == false) { Right = false; moveableObject.ChangeVelocity(0, null); } if (stateKey.IsKeyDown(Keys.Up) && moveableObject.Velocity.Y == 0) { Jump = true; moveableObject.ChangeVelocity(null, -7.8f); } if (stateKey.IsKeyUp(Keys.Up)) { Jump = false; } if (stateKey.IsKeyDown(Keys.Space)) { Shoot = true; } if (stateKey.IsKeyUp(Keys.Space)) { Shoot = false; } if (moveableObject.Velocity.Y != 0) { moveableObject.ChangeVelocity(null, moveableObject.Velocity.Y + 0.2f); } moveableObject.Position += moveableObject.Velocity; if (!moveableObject.TouchingGround && moveableObject.Velocity.Y == 0) { moveableObject.ChangeVelocity(null, 0.2f); } }
private Vector GetResultingVelocityFromGravity(IMoveableObject objectA, IEnumerable<IMoveableObject> moveableObjects) { Vector gravity = new Vector(); foreach (IMoveableObject objectB in moveableObjects.Where(objectB => objectB != objectA)) { double distance = VectorUtils.GetDistance(objectA, objectB); double angle = (2 * Math.PI) - AngleUtils.ConvertToRadians(Vector.AngleBetween(new Vector(1, 0), objectB.Position - objectA.Position)); double magnitude = (G * objectA.Mass * objectB.Mass) / (distance * distance); gravity += VectorUtils.GetVector(magnitude, angle); } return gravity; }
public override void NetworkStart() { if (IsServer) { enabled = false; } else { Controller = GetComponent <IMoveableObject>(); MoveSpeed = Controller.GetMoveSpeed(); transform.position = Controller.GetNetworkPosition(); } }
/// <summary> /// Volgt het meegegeven object zodat deze steeds in het midden van het scherm blijft /// </summary> /// <param name="Character"></param> /// <param name="screenWidth"></param> /// <param name="screenHeight"></param> public void Follow(IMoveableObject Character, int screenWidth, int screenHeight) { Matrix scale = Matrix.CreateScale(Zoom, Zoom, 1); var position = Matrix.CreateTranslation( -Character.Position.X - (Character.CollisionRectangle.Width / 2), -Character.Position.Y - (Character.CollisionRectangle.Height / 2), 0); var offset = Matrix.CreateTranslation( screenWidth / 2 / Zoom, screenHeight / 2 / Zoom, 0); Transform = position * offset * scale; }
public override void NetworkStart() { Rb = GetComponent <Rigidbody2D>(); if (!IsServer) { enabled = false; Destroy(Rb); } else { Controller = GetComponent <IMoveableObject>(); Controller.UpdateVelocityDirection += OnClientChangeDirection; MoveSpeed = Controller.GetMoveSpeed(); } }
public void SetTarget(IMoveableObject target) { Target = target; }
public TurboShip(IMoveableObject space_ship) : base(space_ship) { }
public SpaceShipDecorator(IMoveableObject space_ship) { this.space_ship = space_ship; }
// Update is called once per frame void Update() { matchWaitTimer -= Time.deltaTime; if (matchWaitTimer < -600) { matchWaitTimer = 0f; } if (wait >= 0) { wait -= Time.deltaTime; } if (instantiatedMatch == null) { if (Input.GetKeyDown(KeyCode.Q)) { if (matchWaitTimer <= 0) { LightMatch(); } } } else { if (Input.GetKeyDown(KeyCode.Q)) { DropMatch(); } } if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out currentHit, Mathf.Infinity, LayerMask.GetMask("Object"))) { IMoveableObject clickedObj = currentHit.collider.GetComponent <IMoveableObject>(); if (clickedObj != null && wait < 0) { if (Input.GetMouseButton(0) && !clickedObj.IsHeld()) { clickedObj.OnClicked(); if (clickedObj.IsHeld()) { clickedObjHeld = clickedObj; } wait = 2; } if (!clickedObj.IsHeld()) { clickedObj.OnMouseHover(); } } } if (Input.GetMouseButtonDown(0) && clickedObjHeld != null && wait < 0) { clickedObjHeld.OnThrown(); clickedObjHeld = null; wait = 2; } if (!Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); Vector3 angleToChangeCamera; if ((mouseMovement.y * mouseSensitivityFactor) > 5) { angleToChangeCamera = new Vector3(5, 0f, 0f); } else if ((mouseMovement.y * mouseSensitivityFactor) < -5) { angleToChangeCamera = new Vector3(-5, 0f, 0f); } else { angleToChangeCamera = new Vector3(mouseMovement.y * mouseSensitivityFactor, 0f, 0f); } if (sceneCamera.eulerAngles.x > 355 && mouseMovement.y > 0) { sceneCamera.eulerAngles -= angleToChangeCamera; } else if (sceneCamera.eulerAngles.x >= 0 && sceneCamera.eulerAngles.x <= 30 && mouseMovement.y > 0) { sceneCamera.eulerAngles -= angleToChangeCamera; } else if (sceneCamera.eulerAngles.x >= 350 && sceneCamera.eulerAngles.x >= 0 && mouseMovement.y < 0) { sceneCamera.eulerAngles -= angleToChangeCamera; } else if (sceneCamera.eulerAngles.x < 25 && mouseMovement.y < 0) { sceneCamera.eulerAngles -= angleToChangeCamera; } transform.eulerAngles += new Vector3(0f, mouseMovement.x * mouseSensitivityFactor, 0f); if (!changedTransform) { if (mouseMovement != new Vector2(0f, 0f)) { changedTransform = true; } else { changedTransform = false; } } } //updating animator variables to the bools within the character controller /*myAnimator.SetBool("IsWalking", isWalking); * myAnimator.SetBool("IsRunning", isRunning); * myAnimator.SetBool("IsJumping", isJumping); * myAnimator.SetBool("IsBack", isBack); * myAnimator.SetBool("IsRight", isRight); * myAnimator.SetBool("IsLeft", isLeft);*/ GetComponent <Rigidbody>().angularVelocity = Vector3.zero; GetComponent <Rigidbody>().velocity = Vector3.zero; }
public abstract void Update(IMoveableObject hero);
// Update is called once per frame void Update() { if (wait >= 0) { wait -= Time.deltaTime; } if (instantiatedMatch == null) { if (Input.GetKeyDown(KeyCode.Q)) { LightMatch(); } } else { if (Input.GetKeyDown(KeyCode.Q)) { DropMatch(); } } agentTarget.position = transform.position; agentTarget.position = RotateDestination(GetDirection(), agentTarget.position); agent.destination = agentTarget.position; heldObject.position = RotateDestination(new Vector3(-.5f, 1.5f, 2.5f), transform.position); heldObject.position = RotateDestination(GetDirection(), heldObject.position); if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out currentHit, Mathf.Infinity, LayerMask.GetMask("Default"))) { IMoveableObject clickedObj = currentHit.collider.GetComponent <IMoveableObject>(); if (clickedObj != null && wait < 0) { if (Input.GetMouseButton(0) && !clickedObj.IsHeld()) { clickedObj.OnClicked(); if (clickedObj.IsHeld()) { clickedObjHeld = clickedObj; } wait = 2; } if (!clickedObj.IsHeld()) { clickedObj.OnMouseHover(); } } } if (Input.GetMouseButtonDown(0) && clickedObjHeld != null && wait < 0) { clickedObjHeld.OnThrown(); clickedObjHeld = null; wait = 2; } if (!Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); sceneCamera.eulerAngles -= new Vector3(mouseMovement.y * mouseSensitivityFactor, 0f, 0f); transform.eulerAngles += new Vector3(0f, mouseMovement.x * mouseSensitivityFactor, 0f); if (!changedTransform) { if (mouseMovement != new Vector2(0f, 0f)) { changedTransform = true; } else { changedTransform = false; } } } //updating animator variables to the bools within the character controller myAnimator.SetBool("IsWalking", isWalking); myAnimator.SetBool("IsRunning", isRunning); myAnimator.SetBool("IsJumping", isJumping); GetComponent <Rigidbody>().angularVelocity = Vector3.zero; GetComponent <Rigidbody>().velocity = Vector3.zero; }
public static double GetAngle(IMoveableObject objectA, IMoveableObject objectB) { double distance = VectorUtils.GetDistance(objectA, objectB); double distanceY = objectA.Position.Y - objectB.Position.Y; return Math.Asin(distanceY / distance); }