Code:
Problem description:
The native BYOND pixel movement system does not seem to have any sort of support for angled movement or specification of velocity values. This is pretty important especially in the case of projectiles and whatnot.
Is there a way to simulate this in within BYOND's native pixel movement, or am I missing something?
ID:1330017
Jul 20 2013, 2:58 pm (Edited on Jul 20 2013, 3:04 pm)
(See the best response by DarkCampainger.)
|
|
Jul 20 2013, 3:03 pm
|
|
There was ways to simulate it before pixel movement. Especially velocity, that is pretty easy. Angles are a little harder unless you know the math that it involves.
|
I am familiar with trigonometric and vector projection, I am just curious if I can pull this off with native pixel movement, or if I have to rely on something like FA's library.
|
Of course you can. Utilize Move()'s new arguments to set the step_x and step_y. I would also advise changing the step_size each step, because a step bigger than step_size is a jump, not a slide.
|
I don't understand what you're asking. Do you want to move based on the angle you're in, or do you want a projectile to travel in a specific direction?
If it's the first, using law of cosines, it's as simple as this: player.x += speed * cos(angle) player.y += speed * sin(angle) If it's the latter, get the vector between the target and the projectile using the formula arccos(p * t / (|p| * |t|)), or you could use Lummox JR's atan2(), which is pretty much the same thing. |
BYOND's built-in step_x/y values are automatically floored to integer values, so you'll want to track them yourself or use an accumulator. Then you can use Move() like Albro1 suggested (Example). So long as the movement is less than one tile size, it should properly "slide" it for you, but I haven't fiddled with it much.
Also, normalizing a vector is probably cheaper than atan2(), sin(), and cos(). |
In response to DarkCampainger
|
|
If you set step_size to a large enough number, it'll always be a slide and have precise collision.
step_size = max(abs(dx), abs(dy)) |