Hello everyone!
Please help request!
As the title says, i need a object having a constant speed in the X axis!
I leave an attachment example.
Constant speed cube would have to be 480, but no.
I hope you help me!
Constant speed in the X axis of a body
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Constant speed in the X axis of a body
- Attachments
-
- cube.love
- (635 Bytes) Downloaded 220 times
Re: Constant speed in the X axis of a body
in love.physics, bodies have velocity which is decreased when they hit another body, this is why the velocity isnt constant
Re: Constant speed in the X axis of a body
Yep, Doctory is right.
You can overwrite the linear velocity manually each step, but then the collisions would look weird.
You can overwrite the linear velocity manually each step, but then the collisions would look weird.
Re: Constant speed in the X axis of a body
Not getting into collisions... This will move you along at a constant rate:
Code: Select all
love.update(dt)
object.x = object.x + distancePerSecond * dt
object.y = 500
end
Re: Constant speed in the X axis of a body
try your code, this is the result.Beelz wrote:Not getting into collisions... This will move you along at a constant rate:Code: Select all
love.update(dt) object.x = object.x + distancePerSecond * dt object.y = 500 end
it can be improved? Thanks!
Re: Constant speed in the X axis of a body
If you don't want your body to respond to collisions but move at a constant rate you can make it a "kinematic" body and set its velocity.
Kinematic bodies push other objects but do not respond to collisions themselves.
Kinematic bodies push other objects but do not respond to collisions themselves.
it can be improved? Thanks!
Code: Select all
love.update(dt)
local lvx, lvy = object:getLinearVelocity()
object:setLinearVelocity(10, lvy)
end
Re: Constant speed in the X axis of a body
Thanks, but I want to respect collisions!ivan wrote:If you don't want your body to respond to collisions but move at a constant rate you can make it a "kinematic" body and set its velocity.
Kinematic bodies push other objects but do not respond to collisions themselves.
it can be improved? Thanks!Code: Select all
love.update(dt) local lvx, lvy = object:getLinearVelocity() object:setLinearVelocity(10, lvy) end
With "kinematic" this happens:
In the left top corner see that the speed is constant!
but does not respect the collision!
I need collision respect, at the same time, keep constant speed.
-----------------------------------
This respects the collision, but no speed!
also thanks.
Re: Constant speed in the X axis of a body
switch from the love.physics, it is impossible to get a constant velocity in love.physics without screwing something up
Re: Constant speed in the X axis of a body
Not really, he just needs to do a few things every frame:Doctory wrote:switch from the love.physics, it is impossible to get a constant velocity in love.physics without screwing something up
- get current velocity vector (:getLinearVelocity())
- normalize and scale it by the target velocity
- subtract the actual velocity from the target velocity vector
- apply a force proportional to that difference
Re: Constant speed in the X axis of a body
1.you set the linear velocityZ_ReC wrote:This respects the collision, but no speed!
2.you update the simulation
3.the linear velocity changes due to collisions with the floor
So you're going in the update 'step' with the desired velocity
and collisions happen which slow down the body.
There is no simple way to work around this
if you want to have 'realistic'-looking collisions.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], RetroKevin and 9 guests