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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:42:01+00:00 2026-05-25T16:42:01+00:00

I’m building a little tower-defense game with some friends in Java. Now I’m assigned

  • 0

I’m building a little tower-defense game with some friends in Java. Now I’m assigned with the logic for towers and at the moment I’m trying to figure out how a tower has to turn to aim and hit a target monster. Because a monster moves on while the tower is turning and shooting, it needs to aim for a future position. I’ve implemented a function, which gives me the position of a monster at any time t and also a function, which gives me the smaller angle needed to turn to a monster, but now I’m confused because there are three unknown variables:

  • t1 or angle: the time or angle, the tower needs to turn (the speed at which a tower can turn is given)
  • t2 or shoot distance: the time a bullet needs to travel to hit the target (speed also given, constant).
  • t3 or travel distance: the distance the monster travels in the same time.

So I’m searching for a solution for:

min(t1+t2) = min(t3)

where the target monster is still in range of the tower. I already thought of calculating with the maximal needed turn and maximal possible range and then stepwise decrementing, but I’m curious if there is a “perfect” non-heuristic solution?

  • 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-25T16:42:02+00:00Added an answer on May 25, 2026 at 4:42 pm

    ADDED INFO:

    I assume that a given monster has distance D to the tower, moves on the shortest path to the tower, and the tower starts turning towards the monster. This is the situation at t=0.

    FIXED TYPOS:

    If your tower turns with an angular speed omega, that is, the angle phi at time t is

    phi = omega * t
    

    So if you know that your tower has to turn an angle phi, the bullet will be shot at

    t = phi/omega
    

    From this on the distance which the bullet speed v has traveled is

    s(t) = v * (t-phi/omega)
    

    If your monster moves with a speed vm, the monster will be
    at distance d

    d(t) = D - vm * t
    

    The bullet hits the monster if

    s(t) = d(t)
    

    This equation is easy to solve: just substitute d(t) and s(t) and rearange the terms for getting t:

    t = (D + v * phi/omega) / (phi/omega + vm)
    

    And the bullet will have traveled s(t) at this moment. If this value is negative, the monster was too fast and reached the tower before the bullet was fired

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build

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.