Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7760655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:56:50+00:00 2026-06-01T13:56:50+00:00

I got an object (called tempEnemy) which is flying around and shooting. The problem

  • 0

I got an object (called tempEnemy) which is flying around and shooting.
The problem is that I can’t keep the value tempEnemy.rotateTo positive, i.e.
it shall be between 0 and 359 degrees. Currently rotateTo ranges from:
rotateTo < 0 (bug) && rotateTo > 0 && rotateTo > 359 (bug).

tempEnemy.dX = tempEnemy.destX - tempEnemy.x;
tempEnemy.dY = tempEnemy.destY - tempEnemy.y;

//I added 180 because my tempEnemy object was looking and shooting to the wrong direction
tempEnemy.rotateTo = (toDegrees(getRadians(tempEnemy.dX, tempEnemy.dY))) + 180; 

if (tempEnemy.rotateTo > tempEnemy.frame + 180) tempEnemy.rotateTo -= 360;
if (tempEnemy.rotateTo < tempEnemy.frame - 180) tempEnemy.rotateTo += 360;

tempEnemy.incFrame = int((tempEnemy.rotateTo - tempEnemy.frame) / tempEnemy.rotateSpeed);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:56:51+00:00Added an answer on June 1, 2026 at 1:56 pm

    You can always use the modulo operator (%) to keep a value positive. The module calculates the rest of a division.

    E.g. (example works with integers there for a division always has a left over.)

    19 % 5 = 4
    

    Because in the number 19 5 only fits 3 times (3 * 5 = 15,, 4 * 5 = 20,, 20 is too high) the left over is 4 (19 - 15). That is the modulo.

    Extra examples:

    7 % 3 = 1
    15 % 4 = 3
    21 % 9 = 3
    

    The output of a modulo operation is never higher then the right hand operator – 1 There for it is perfect for your problem.

    If your object is rotated 1234 degrees,, then operate it with a modulo 360 to get the respective number between 0 and 360 for it.

    1234 % 360 = 154
    

    Other more easier examples:

    720 % 360 = 0
    360 % 360 = 0
    540 % 360 = 180
    -180 % 360 = 180
    -720 % 360 = 0
    -540 % 360 = 180
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got an object, which is called in my form1-window. How can I change
I've got a simple class called object that I'm having a problem with. Theres
I've got a value object, which stores info for example amount. The getAmount() getter
I've an object which is called Uczestnik which just got saved to database var
I've got a NULLPointerException. I have iplemented an object called Workhours, which has list
I've got an object, which I'll call MyObject. It's a class that controls a
I've got a PHPUnit mock object that returns 'return value' no matter what its
I got the following problem: I have an object called tempScore for my game.
I've got an object which is a new MimeMessage called message and I want
ive got an object that looks like this with print_r(): SimpleDOM Object ( [0]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.