Basically I'm trying to diplay an arrow (pointing in the direction the ball is traveling) at the end of the yellow movement vector, I'm almost there but as you can see, one of the 2 "pointy-lines" of the arrow is pointing 270° instead of 90°.
If I negate the Y for that "pointy-line"in the code, it solve that particular case but as soon as the ball bounce the wall, the resoult is mirrored again, so I think it has to do with the circle's quadrants or something.
How do you guys achieve this the smart way?
Code: Select all
local function showDirection(entity, lineLenght)
--find center pivot
local lineStartX = entity.x + entity.width / 2
local lineStartY = entity.y + entity.height / 2
--find length of vector
local lineEndX = lineStartX + entity.direction.x * entity.speed * lineLenght
local lineEndY = lineStartY + entity.direction.y * entity.speed * lineLenght
--main line
love.graphics.setColor(235, 235, 0, 255)
love.graphics.line(lineStartX, lineStartY, lineEndX, lineEndY)
--degAngle is the angle of the movement vector range 0°-360°
local degAngle = helpers.findDegAngle({ x = lineStartX, y = lineStartY }, { x = lineEndX, y = lineEndY })
--arrow line 1
local Radius = math.sqrt(math.pow(lineEndX - lineStartX, 2) + math.pow(lineEndY - lineStartY, 2)) / 3
local arrow1Angle = (degAngle + 135) % 360
local line1X = lineEndX + Radius * math.cos(math.rad(arrow1Angle))
local line1Y = lineEndY + Radius * math.sin(math.rad(arrow1Angle))
love.graphics.line(lineEndX, lineEndY, line1X, line1Y)
--arrow line 2
local arrow2Angle = (degAngle + 225) % 360
local line2X = lineEndX + Radius * math.cos(math.rad(arrow2Angle))
local line2Y = lineEndY + Radius * math.sin(math.rad(arrow2Angle))
love.graphics.line(lineEndX, lineEndY, line2X, line2Y)
end