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 6718217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:56:35+00:00 2026-05-26T08:56:35+00:00

Making a ship game because I am incredibly original.. With that aside, I have

  • 0

Making a ship game because I am incredibly original.. With that aside, I have a problem. I have a function to fire bullets from my ship based on its rotation which works.. it uses this code on creation:

        var b = new Bullet  ;
        b.x = x;
        b.y = y;
        b.rotation = rotation;
        parent.addChild(b);
        bullets.push(b);
        score -=  50;
        trace(enemybullets[30].x + "," + enemybullets[30].y);

The above code is in my Ship class so I can easily make the bullets achieve the correct rotation.
And to continually update its position, in the bullet’s class:

        x += Math.cos(rotation / 180 * Math.PI) * speed;
        y += Math.sin(rotation / 180 * Math.PI) * speed;

So that all works well. But I have another class, EnemyBullet, which randomly generates and uses similar code to set its direction and movement. In my ship class:

        var eb = new EnemyBullet ;
        eb.x = (Math.random() * 550) - 550;
        //trace("eb.x is " + eb.x)
        eb.y = (Math.random() * 400) - 400;
        //trace("eb.y is " + eb.y);
        var a1 = eb.y - y;
        var b1 = eb.x - x;
        var radians1 = Math.atan2(a1,b1);
        var degrees1 = radians1 / Math.PI / 180;
        eb.rotation = degrees1;
        if (enemybullets.length < 50)
        {
            parent.addChild(eb);
            enemybullets.push(eb);
        }

And in the EnemyBullet class:

        x += Math.cos(rotation / 180 * Math.PI) * speed;
        y += Math.sin(rotation / 180 * Math.PI) * speed;

I have set up a trace to track where one of my bullets going, because they certainly aren’t appearing on my screen.. here are the results from my tracing:

x: 121.55, y:-162.05
x: 1197.05, y:-162.05
x: 1842.35, y:-162.05
x: 2368.15, y:-162.05
x: 2547.4, y:-162.05
x: 2702.75, y:-162.05
x: 2882, y:-162.05

I gather that the rotation is therefore always horizontal, but can’t for the life of me see why? Can anyone give me an answer? Assuming it’s simple enough because the code I used to setup the rotation is the same working code I have used to turn a movieclip towards the mouse..

Any ideas?

Ta!

  • 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-05-26T08:56:36+00:00Added an answer on May 26, 2026 at 8:56 am

    The conversion from radians to degrees contains a bug:

    var degrees1 = radians1 / Math.PI / 180;
    

    Should be:

    var degrees1 = radians1 / Math.PI * 180;
    

    Or to make it more understandable:

    var degrees1 = 180 * radians1 / Math.PI;
    

    In your case degrees1 probably is value near 0; so movement is always horizontal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making websites that appear correctly in IE is a big problem. Is there any
I'm making a 2D sidescrolling space shooter-type game, where I need a background that
I'm making a simple game in XNA (for Windows, if that makes a difference),
Making a small WCF test program which is based on a Store that has
I'm making a game and I need to be able to ship some data
I'm making a game like Arkanoid and to move the ship with mouse, I'm
Making my first game and it is along the lines of Advance Wars/Fire Emblem.
Making a word document of our network set-up. We have about 7 servers and
Making an adobe flex ui in which data that is calculated must use proprietary
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created

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.