Constant speed in the X axis of a body

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Z_ReC
Prole
Posts: 7
Joined: Sat Nov 14, 2015 2:48 am

Re: Constant speed in the X axis of a body

Post by Z_ReC »

First:
Thanks to all who helped! :crazy:

Second:
S0lll0s wrote:
Doctory wrote:switch from the love.physics, it is impossible to get a constant velocity in love.physics without screwing something up
Not really, he just needs to do a few things every frame:
  • get current velocity vector (:getLinearVelocity())
  • normalize and scale it by the target velocity
Now you can either just set it directly (setLinearVelocity()), which might look weird, or instead apply a force:
  • subtract the actual velocity from the target velocity vector
  • apply a force proportional to that difference
Try to duplicate your example, but I could not, you could guide me more? Sorry!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Constant speed in the X axis of a body

Post by s-ol »

If you don't want to mess with the velocity itself you basically read the current velocity, and if it's too slow, apply a force to the right, if its too fast, apply a force to the left to slow it down.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 206 guests