View Single Post
  #1   Spotlight this post!  
Unread 14-02-2011, 19:26
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,100
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Acceleration based on position


Let XU be the upper position limit.

Let XL be the lower position limit.

Let X be the current position, between those limits.

Let K be the size of the "speed zone" near either limit, where speed gets reduced.

Let J be the joystick command, between -1 and +1, where +1 commands a speed toward the upper limit.

Then:

Code:
if ( (X>XU-K) && (J>(XU-X)/K) ) J=(XU-X)/K;
else
if ( (X<XL+K) && (J<(XL-X)/K) ) J=(XL-X)/K;

Reply With Quote