Jump to content
IGNORED

Is there a fancy way to get the distance between two objects?


Random Terrain

Recommended Posts

Is there a better way to get the distance between two objects than using something like this?

 

   if player0y > missile0y then temp6 = player0y - missile0y
   if missile0y > player0y then temp6 = missile0y - player0y

 

Seems like there would be a fancy math way that doesn't require two if-thens.

Link to comment
Share on other sites

You might be thinking of the 'absolute value' math function found in most programming languages:

    temp = abs(player0y - missile0y)

 

Which in bBasic, would be:

    temp6 = player0y - missile0y

    if temp6{7} then temp6 = -temp6         ;-- IF value is negative, THEN make it positive.

 

 

NOTE:  If the distance is greater than 127, this doesn't work, since big values would be interpreted as negative values due to the byte range limit.

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...