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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:39:16+00:00 2026-05-20T21:39:16+00:00

I am having trouble diagnosing the following issue. There are 2 objects, a ring

  • 0

I am having trouble diagnosing the following issue.

There are 2 objects, a ring and a target. The ring represents a ship and the target represents the destination. When the user clicks anywhere in the window, the target is placed where you click and the ship then moves to that location. The problem that I am having is the further the ship has to move, the more velocity that ship will achieve, thus overshooting its target. The further the ship has to move translates to a slower deceleration. I am not sure where this is happening. I have provided the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ArtificialDumb
{
    class PhysicsObject
    {
        public Vector2 Position;
        public Vector2 OldPosition;

        public float Mass;

        public Vector2 Acceleration;

        public float Drag = 0.01f;

        public PhysicsObject(float x, float y)
        {
            Position = OldPosition = new Vector2(x, y);
        }

        public PhysicsObject(Vector2 pos)
        {
            Position = OldPosition = pos;
        }

        public virtual void Update()
        {
            Vector2 velocity = Position - OldPosition;

            velocity *= (1 - Drag);

            OldPosition = Position;
            Position += velocity;

            Position += Acceleration;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ArtificialDumb
{
    class Ship : PhysicsObject
    {
        public float MaxThrust;

        public Vector2 Target;

        public Ship(Vector2 pos)
            : base(pos)
        {
            MaxThrust = 50f;
            Mass = 100;
        }

        public override void Update()
        {
            Vector2 diff = Target - Position;
            Vector2 Velocity = (Position - OldPosition);


            // Dark Magic. Do Not Touch.
            // This is the equation for projectile velocity. -ASR
            // Edited for correct float value -ASR
            // people keep touching! - AgH
            Vector2 thrust = diff - (Velocity * Velocity.Length() * 0.75f);

            thrust.Normalize();
            // todo: Account for when we don't need to use maximum thrusters
            thrust *= MaxThrust;

            Acceleration = thrust / Mass;
            base.Update();
        }
    }
}
  • 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-20T21:39:16+00:00Added an answer on May 20, 2026 at 9:39 pm

    This is less trivial than it seems. What makes it hard is you have to make your ship end up at the right position, with 0 velocity.

    If you want to do it right and aren’t afraid of maths, implement a PID controller. This is the standard way to solve these kinds of problems. It is uesd often in the industry for things such as autopilots.

    However there is an easier way!

    If you are already travelling straight towards your target, you can calulate where you will end up if you started decelerating now.
    Assuming your deceleration is constant:

    endPos = Position + (Velocity * Velocity) / (2 * deceleration);
    

    endPos is where you would end up if you started braking now. You can compare it to your target to see if you are currently overshooting or undershooting.

    If you know that you need to brake, you can calculate exactly how much you need to brake to arrive at your target by rearranging the above formula:

    deceleration  = (Velocity * Velocity) / (2 * (endPos - Position));
    

    The deceleration here is the ‘thrust’ that you need to give your ship to stop where you want it to.

    I hope this helps, please tell me if you don’t understand anything, or want an explanation to how I came up with the above formulas.

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

Sidebar

Related Questions

Having trouble working out how to do the following - I want to list
Having trouble with an HQL query. If I remove the avg(..) from it it
Having trouble setting the value of a declared variable in MySQL. If I run
Im having trouble getting my head round subqueries in Mysql. Fairly simple ones are
im having trouble extracting the trend name and search query from the json response
I am having trouble with a camera class I am trying to use in
I am having trouble accessing the document in my firefox extension. I am trying
I'm having trouble finding the GameKit api that contains the Game Center Reference. Apple
I'm having trouble trying to implement a shared method/property between two classes created by
I'm having trouble installing Django, even if I follow the instructions here: http://www.djangobook.com/en/2.0/chapter02/ Could

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.