WorldX
Introduction
Code Example - Moving an Entity with the Cursor
// This example assumes a Screen which contains PlayerInstance
void CustomActivity(bool firstTimeCalled)
{
var cursor = GuiManager.Cursor;
PlayerInstance.X = cursor.WorldX;
PlayerInstance.Y = cursor.WorldY;
}Code Example - Moving an Entity towards the Cursor
var cursor = FlatRedBall.Gui.GuiManager.Cursor;
if(cursor.PrimaryDown)
{
var cursorPosition = new Vector3(cursor.WorldX, cursor.WorldY, 0);
var directionToPlayer = cursorPosition - PlayerInstance.Position;
var normalized = directionToPlayer.NormalizedOrZero();
float movementVelocity = 60;
PlayerInstance.Velocity = normalized * movementVelocity;
}
else
{
PlayerInstance.Velocity = Vector3.Zero;
}
Last updated
Was this helpful?