Code: Select all
x = math.sin(math.rad(angle))
Code: Select all
x = math.sin(math.rad(angle))
Code: Select all
rads = math.rad(angle)
x = math.cos(rads)*radius + offsetx
y = math.sin(rads)*radius + offsety
Code: Select all
local function rotatePoint(cx,cy,px,py,angle)
local s = math.sin(angle)
local c = math.cos(angle)
px,py = px-cx,py-cy
return px*c - py*s + cx,px*s + py*c + cy
end
function love.draw()
local cx,cy = 100,100 --center of rotation
local px,py = 150,100 --point that is being rotated
local angle = love.timer.getTime()
local rx,ry = rotatePoint(cx,cy,px,py,angle) --point after rotation
local radius = math.sqrt((px-cx)^2+(py-cy)^2)
love.graphics.setColor(255,255,255,255)
love.graphics.circle("line",cx,cy,radius)
love.graphics.setColor(0,255,0,255)
love.graphics.arc("line","open",cx,cy,radius/2,0,angle%(math.pi*2))
love.graphics.setColor(0,0,255,255)
love.graphics.line(cx,cy,px,py)
love.graphics.points(cx,cy,px,py)
love.graphics.setColor(255,0,0,255)
love.graphics.line(cx,cy,rx,ry)
love.graphics.points(rx,ry)
end
Code: Select all
--load
angle = 1 -- in degrees I use it as math.random(1,360) to get random starting spot
X, Y = ObjectInMiddleX + math.cos(angle) * DistanceYouWantObjectToBeFromMiddle, ObjectInMiddleY + math.sin(angle) * DistanceYouWantObjectToBeFromMiddle
--update
angle = angle + (SpeedYouWantToOrbit *dt)
--then you have to update the x, and y too
X, Y = ObjectInMiddleX + math.cos(angle) * DistanceYouWantObjectToBeFromMiddle, ObjectInMiddleY + math.sin(angle) * DistanceYouWantObjectToBeFromMiddle
You're mixing up the sin and cos though; x gets cos, y gets sin, like with the examples given above yours.
Users browsing this forum: No registered users and 1 guest