Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Smooth Movement to (0,0,0)?

  1. Mar 27, 2010 #1
    Hey there! I'm working on a bit of a game modification, and I'm looking for a little help with some physics-related math. I'm only in my second year of high-school physics, so I'm not completely sure where to go with this question. And sorry if this is in the wrong forum.

    Essentially, I'm trying to rotate an object to how the player is looking. To achieve this, I was originally doing a little bit of math to find the angular difference, and just using a damped spring equation to rotate the object back to how I want it fairly smoothly. Quite simple. The only problem with this is that it steadily slows down as it approaches the angle (0,0,0), never quite stopping or reaching the angle, which makes sense for this equation.

    Unfortunately, I'd like the object to uniformly accelerate and uniformly decelerate back to (0,0,0). Differing acceleration and deceleration speeds are necessary, as well as a top speed. Since this is a computer, I can only run so many calculations per second, and I can ignore drag and gravity if I so choose. The player may also choose to change the direction in the middle of the trip back to zero, which would, of course, be necessary to take into account. I realize this may seem a bit demanding, but it's really what's necessary to solve this.

    The actual game-use of this is to turn an aircraft to where the player is looking. The turning of their view in conjunction with this is already compensated for. However, I'm sure I'll find some other uses for this in the future, so it's quite beneficial.

    A real-world analogy of this would be having a car, say, 50 meters away from a line, which can accelerate and decelerate at certain speeds, and having the car evenly accelerate to a point, then decelerate from that point to a full stop. The line may move mid-trip, which would have to be taken into account, and only so many calculations (say 10) can be done per second.

    Logically, this should seem easier, but I'm honestly at a bit of a loss as to what equations I should use for this. If this is an impossibility for me/out of my scope, I can always go back to my simpler equations, but I would very much prefer a better solution. I've been looking for a solution to this for a couple weeks now, and I haven't been able to find anything. It's really been quite a learning experience, that's for sure, but I'd like to finally put this problem away. Any help would be very much appreciated.
  2. jcsd
  3. Mar 28, 2010 #2


    Staff: Mentor

    I don't really understand your question, especially the use of vector notation to describe an angle. However, the equation for uniform acceleration is:
    [tex]x(t) = \frac{1}{2}a t^2 + v_0 t + x_0[/tex]
    where [itex]x_0[/itex] is the initial position, [itex]v_0[/itex] is the initial velocity, and [itex]a[/itex] is the acceleration. Since you want uniform acceleration followed by uniform deceleration you will have to use this equation twice, once for the acceleration stage and once for the deceleration stage. You will need to make sure that the position and velocity of the two stages are equal at the time that you switch between them.
  4. Mar 28, 2010 #3
    Feel free to completely ignore that it is an angle and treat it completely like a vector. That's why I put in the real-world comparison. There isn't a difference in this scenario. And I was originally going to do that solution, but would that not require me to do a pair of square roots? I was trying to avoid square roots, if possible. I'm also not sure if the delta time is going to be completely stable, which could mess that up when it reaches zero. Because of the wait time in calculations, you would overshoot, then overshoot back, and would just jitter there, trying to reach zero. I'm probably not explaining this very well.

    Ideally the velocity-time graph would be a simple upside-down V. This would mean locating the peak of the graph would be easy. However, even if I know where it is, if it doesn't line up with the calculation times (picture a bunch of vertical lines on the graph), then I would not be able to apply the correct deceleration force at the correct time. I could theoretically get past this by predicting the acceleration/deceleration in that time period and adding them, but once I reach zero, I think this method would break down. If the deltatime (time between calculations) is inconsistent, then I believe it is impossible. Ideally, there would be a simple method to bypass this (such as the damped spring equation), but I'm not entirely sure that there is. And if there is, I'm not sure if it lies entirely in the realm of physics.
    Last edited: Mar 28, 2010
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Smooth Movement to (0,0,0)?
  1. Time at t = 0 (Replies: 11)