Looking in direction pointing line
This commit is contained in:
@@ -97,6 +97,12 @@ namespace DepthsBelow.Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float Rotation;
|
public float Rotation;
|
||||||
|
|
||||||
|
public void Rotate(int directionX, int directionY)
|
||||||
|
{
|
||||||
|
Rotation = (float)Math.Atan(directionY/directionX);
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 Origin;
|
public Vector2 Origin;
|
||||||
|
|
||||||
public static implicit operator Vector2(WorldTransform worldTransform)
|
public static implicit operator Vector2(WorldTransform worldTransform)
|
||||||
|
|||||||
@@ -87,15 +87,17 @@ public MouseInput(Core core)
|
|||||||
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
if (unit.Selected)
|
if (unit.Selected)
|
||||||
|
{
|
||||||
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
|
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ms.RightButton == ButtonState.Pressed)
|
if (ms.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
{
|
{
|
||||||
if (unit.Selected)
|
if (unit.Selected && gridRectangle.Intersects(unit.GetComponent<Component.Collision>().Rectangle))
|
||||||
{
|
{
|
||||||
checkingDirection = true;
|
checkingDirection = true;
|
||||||
directionStart = unit.Transform.World + unit.Transform.World.Origin;
|
directionStart = unit.Transform.World + unit.Transform.World.Origin;
|
||||||
@@ -104,8 +106,28 @@ public MouseInput(Core core)
|
|||||||
}
|
}
|
||||||
if (checkingDirection == true && ms.RightButton == ButtonState.Pressed)
|
if (checkingDirection == true && ms.RightButton == ButtonState.Pressed)
|
||||||
{
|
{
|
||||||
directionNow.X = ms.X;
|
foreach (var unit in core.Squad)
|
||||||
directionNow.Y = ms.Y;
|
if (unit.Selected)
|
||||||
|
{
|
||||||
|
directionNow.X = mouseWorldPos.X;
|
||||||
|
directionNow.Y = mouseWorldPos.Y;
|
||||||
|
float directionX = mouseWorldPos.X - unit.Transform.World.X;
|
||||||
|
float directionY = mouseWorldPos.Y - unit.Transform.World.Y;
|
||||||
|
var mouseDirection = mouseWorldPos;
|
||||||
|
mouseDirection.Normalize();
|
||||||
|
//float angle = (float)Math.Acos(Vector2.Dot(new Vector2(0, 1), mouseDirection)) * MathHelper.TwoPi;
|
||||||
|
/*if (directionX < 0)
|
||||||
|
{
|
||||||
|
directionX *= -1;
|
||||||
|
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan(directionY / directionX);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*/unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y, mouseWorldPos.X - unit.Transform.World.X);/*
|
||||||
|
}*/
|
||||||
|
//Console.WriteLine(angle);
|
||||||
|
//unit.GetComponent<Component.Transform>().World.Rotation = angle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user