Hi im trying to make a simple RTS like game.
Current state is that the character can move when iam click on a place on the screen, it moves in its on pace. i can rotate by manually changing the var.
The problem is that i need the character to turn i the direction that its moving in.
I have read about trigonometri an have some basic knowledge
It more of a math/logical problem but im hoping u can help
// David
character movement and angles
Re: character movement and angles
Let's say you have character coordinates at (cx, cy) and target coordinates at (tx, ty).
Then you get:
You also want to set the ox/oy arguments to love.graphics.draw so that it rotates around the center.
EDIT: If you don't have tx or ty and just have a velocity – say, (vx, vy) – then use:
Then you get:
Code: Select all
dx = tx - cx
dy = ty - cy
r = math.atan2(dy, dx)
EDIT: If you don't have tx or ty and just have a velocity – say, (vx, vy) – then use:
Code: Select all
r = math.atan2(vy, vx)
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest