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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:43:55+00:00 2026-05-19T03:43:55+00:00

So essentially what I’ve been trying to do is to get an object (the

  • 0

So essentially what I’ve been trying to do is to get an object (the player) to fire a bullet in a straight line from it in angle and then just continue on, so if the ‘gun’ is pointed at an angle of 35 degrees (with 0 degrees being to the right of the screen adding up to 360 going counter-clockwise) then the bullet will travel at a constant speed (say 5) at that angle from the origin.

Because the way I’ve been doing my movement is I’ve had a function called update that would handle all the drawing and what not. Then when it came to movement it would just add a vertical speed and a horizontal speed to the already existing x and y, and it’s just been too hard to try to work around it so that it adds a suitable horizontal and vertical speed to move at that angle at a constant speed, so any help will be appreciated.
-Heath

  • 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-19T03:43:56+00:00Added an answer on May 19, 2026 at 3:43 am

    Maybe you can make your update() method to measure time since it was last invoked, and update location of bullet based on that?
    It would make bullet to move at approximately constant speed. (given that FPS is big enough)

    EDIT2:

    public class Bullet {
      // speed is in units/second
      // angle is in radians
      double x;
      double y;
      double sv;
      double sh;
      public Bullet(double x, double y, double angle, double speed) {
        this.x = x;
        this.y = y;
        sv = Math.sin(angle)*speed;
        sh = Math.cos(angle)*speed;
        last_updated = System.currentTimeMillis();
      }
    
      long last_updated;
    
      public void update() {
        long time_elapsed = System.currentTimeMillis() - last_updated;
        last_updated = System.currentTimeMillis(); 
        this.x += this.hs*(this.time_elapsed/1000)
        this.y += this.vs*(this.time_elapsed/1000)
      }
    }
    

    Maybe you’ll need to play with angle to make it suitable for your coordinate system. (something like negate the angle, add/substract Pi, and so on.)

    Hope this helps.

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

Sidebar

Related Questions

Essentially Im trying to get many many java clients connect to a socket on
Essentially, what I'm trying to do is to load/draw a map from a Tiled
Essentially, I'm trying to create MIDI's from scratch and put them online. I'm open
essentially i would just like the text of the loaded content. I've been researching
Essentially I'm trying to calculate the bisector line between two points. I've got two
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially, I want to check another object to see if an attribute is set
Essentially, what I'm trying to do is to check the last access time of
Essentially need to read the dependencies programmatically without loading the assembly itself, as then
Essentially I'm trying to combine the two resource declarations into one command. resource :documents,

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.