Problem calcul in BASIC

Page 2/2
1 |

By flyguille

Prophet (3028)

flyguille's picture

25-04-2011, 00:08

so, you can to move a missil sprite guided... Tongue

really you don't needs to convert it to angles.

ok, we have to calculate the relative position from SpriteOwn to SpriteGoal

Ox Oy (sprite own)
Gx Gy (sprite goal)

first, make the observation that both coordinates will affect the proper angle approach.

you first needs to calculate the relativa positon

Rx=Gx-Ox
Ry=Gy-Oy

then you needs to take a FACTOR for each relative.

Rt= Rx+Ry

Then use the factor to do scalation.
Sx=Rx/Rt (it will scales in a range from 0 to 1).
Sy=Ry/Rt (it will scales in a range from 0 to 1).

so, THEN you can to move your sprite OWN to the sprite goal

Ox=Ox + Sx * SpeedFactor
Oy=Oy + Sy * SpeedFactor

now, make sure speedfactor is alway slow than the speed that can to move the sprite goal, because it is a perfect approaching method and don't calculates the kinetic force as a deviation factor.

Make sure Ox & Oy are single presicion type because you needs to accumulate also the fraction part in the sprite position to be accurate.

By flyguille

Prophet (3028)

flyguille's picture

25-04-2011, 00:39

Te same but with kinetic deviation.

Kx Ky = kinetic factors.

Rx=Gx-Ox
Ry=Gy-Oy
Rt= Rx+Ry
Sx=Rx/Rt
Sy=Ry/Rt
Kx=(Sx+Kx*4)/5
Ky=(Sy+ky*4)/5
Kt=Kx+Ky
Ox=Ox+(Sx*(Kx/Kt))* SpeedFactor
Oy=Oy+(Sy*(Ky/Kt))* SpeedFactor

it is not true kinetic, but it do an effect like that..

it basically adds a deviation calculating an average that degradates and upgrades with the last 5 cycles that this formula runs (old factor * 4 + new factor ) / 5, it will act as a delay in the direction, so it sinmulates a kind of kinetic.

oh, I forget, in all formula you needs to check for DIVISION by ZERO error

so if rt = 0 please set it as the minimun
if rt=0 then rt=0.001
if kt=0 then kt=0.001

By DanySoft

Champion (452)

DanySoft's picture

25-04-2011, 14:25

[B]Okay[\B], we have found the same, and the rest in
directions up and down, I will, if so, thank you for your cooperation.LOL! LOL!
Note: your formula will be used to make war game where a spaceship "shoot"to our spaceship, and I will provide collisions.CoolSmileLOL!

By DanySoft

Champion (452)

DanySoft's picture

04-09-2013, 23:07

Hello,
I have a problem: calcul operation on direction X,Y as line!

See this link :Missile Command (1988)

Olther link: Battle Ship Clapton II (1983)

An enemy hit a ship with a missile (sprite).
The problem of programming in the ASM coordinated X, Y for
to reach a spaceship is complicated!

Can you help me? I always use SJASM & Wbass2!

DanySoft

Page 2/2
1 |