Why is drag only applied when acceleration is 0?

Got a question? Need help? Post here!

Why is drag only applied when acceleration is 0?

Postby xxbbcc » Tue Nov 18, 2014 8:59 pm

I'm using Axel 0.9.3 and ran into an issue with my character changing direction while running: drag is not applied to the character because it has acceleration. This is what happens: the character is moving in one direction (let's say right). I press the left arrow to start running left. At this point, acceleration is applied to the character so at first velocity.x decreases and then it turns around.

I also have drag set to imitate friction - when the character is moving (without acceleration), drag kicks in and the character comes to a stop in a short distance. Drag, however, is not applied when there's acceleration - in my above example this leads to the character skidding great distance to the right first and then finally starting to move to the left. The skidding distance is much greater than the 'normal' stopping distance.

Drag is applied in AxEntity.calculateVelocity() which skips applying drag when acceleration is not 0. Why is it done this way?

I'm asking because I'm considering changing this function to apply drag even during acceleration but first I wanted to understand why Axel has it implemented the way it has.
xxbbcc
Sergeant
 
Posts: 20
Joined: Fri Jul 19, 2013 9:02 am

Re: Why is drag only applied when acceleration is 0?

Postby Arkeus » Wed Nov 19, 2014 1:21 am

The short answer: It's changed in 0.9.4 such that it is only skipped if you are accelerating in the direction you are moving. See https://github.com/arkeus/axel-dev for 0.9.4 beta.

Longer answer (in case you can't upgrade):
The biggest reason is that it's not what most games expect, and it requires more intimate knowledge of the inner workings of velocity/acceleration users to see results they expect. A quick example. Let's say someone sets acceleration.x to 10, drag.x to 500 (or something). Typically what people would expect is that while they hold right, they end up with a velocity of 10 after 1 frame, 20 after 2, etc, and when they let go, they decelerate to 0. If drag were applied while you were accelerating, your actual velocity wouldn't match what you set your acceleration to, which can be confusing (and often is for new users). The change in 0.9.4 solves this by still skipping it if you are accelerating in the direction you are moving on the x axis, but applies it if you accelerate in the other direction, which solves the problem you are seeing, (hopefully) without adding confusion.
Image
User avatar
Arkeus
Site Admin
 
Posts: 363
Joined: Mon Mar 26, 2012 12:43 am

Re: Why is drag only applied when acceleration is 0?

Postby xxbbcc » Wed Nov 19, 2014 7:22 am

Arkeus,

Thank you for your reply - you confirmed what I thought may have been the reason behind it. I intend changing it the way you did in 0.9.4 - only apply drag when acceleration points away from direction of movement.

I can't upgrade - my game's well underway and a lot of code has been written with 0.9.3 objects and namespaces but I'll get 0.9.4 and merge over your change. I assume it's only that calculateVlocity() function (firther assuming you haven't refactored that bit) that needs to be merged.
xxbbcc
Sergeant
 
Posts: 20
Joined: Fri Jul 19, 2013 9:02 am


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron