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

  • Home
  • SEARCH
  • 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 6950869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:08:47+00:00 2026-05-27T14:08:47+00:00

I am looking for a way to make my Entity(A bullet) move towards a

  • 0

I am looking for a way to make my Entity(A bullet) move towards a x and y,which is where the player was when the bullet was fired. so In my entity class i have –

   float xSpeed = 1.0F;
   float ySpeed = 0.0F;

if I wanted to move the entity in a diaganal line I would make xSpeed and ySpeed = 1.0F
How would I make it move in the dir of another x and y?

Thanks for the help
EDIT —
Solved,thanks for the help
To anyone else who finds this question needing help,here is my code-

    float xSpeed = 0;
    float ySpeed = 0;

then I have some maths to make it so they move at the same speed

   ySpeed =  ySpeed * (float) (2.5 / Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed));
   xSpeed = xSpeed * (float) (2.5 / Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed));

and this code to set the xSpeed and ySpeed,based on a x and y you want to move towards

    xSpeed = (Game.PlayerX - x) / 3;
    ySpeed = (Game.Playery - y) / 3;

and then,finaly,add xSpeed and ySpeed to the x and y of your entity

    this.x += xSpeed;
    this.y += ySpeed;
  • 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-27T14:08:48+00:00Added an answer on May 27, 2026 at 2:08 pm

    The usual way is to set the relative x and y speeds to cover the required x and y distances in the allotted travel time:

    float xSpeed = (targetLocation.x - currentLocation.x) / travelTime;
    float ySpeed = (targetLocation.y - currentLocation.y) / travelTime;
    

    If you want to travel at a predetermined speed, rather than in a predetermined travel time, do the above computations with travelTime set to some arbitrary value (1.0f would work fine, so you could simply eliminate the division). Then compute this factor:

    float factor = desiredSpeed / Math.sqrt(xSpeed * xSpeed + ySpeed * ySpeed);
    

    (Note that you’ll be dividing by zero if xSpeed and ySpeed are both 0, but that simply indicates that the current and target locations are identical. If that’s a possible condition, you should include an appropriate check.) Finally, readjust xSpeed and ySpeed by the factor:

    xSpeed *= factor;
    ySpeed *= factor;
    

    Note that by setting travelTime to 1, this is just a sneaky way of multiplying the predetermined speed by the sine and cosine of the angle that the travel direction makes with the x axis without mentioning trigonometry at all. 🙂

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

Sidebar

Related Questions

Im looking for a way to make a top bar consistent across activities, allmost
I'm looking for a way to make the search/replace function of VS IDE regex-aware,
I'm looking for a way to make it easy for technically unsophisticated users to
I am looking for a way to make my own login formular in PHP
I am looking for a way to make a request to an XML service
I'm looking for a way to make word-wrap in PHP a bit smarter. So
I am looking for the best way to make my desktop java program run
I'm looking for a lightweight way to make my program (written in C) be
Is there any better way to make this query work? I'm looking for a
I have an entity class: Cabbage.java package womble; public class Cabbage { private int

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.