Edit*
Added video example: https://vimeo.com/340194287
https://love2d.org/wiki/love.physics.newRopeJoint
Creates a joint between two bodies. Its only function is enforcing a max distance between these bodies.
I've created a rope by joining many little circle bodies together. Works quite well.
I've got my player character able to jump and grab one of these points, and originally , was using the RevoluteJoint to join him to the rope body X.
Now I tried to move him up/down the Rope by finding the next body in the rope list and creating a new joint there. I thought a quick way of handling this would be to actually use another RopeJoint - and setting the MaxLength to something small, when the player character had a new joint created on the next rope body, it would just move up to it - due to the MaxLength.
Currently this doesnt happen at all. The next joint is created in the correct place, but my character seems to fall for a moment then reacts to the joint. But the joints MaxLength is playing no role in this. It's like it takes a second for the next RopeJoint to be made - which i dont believe.
Hope I've explained this well enough. Am i miss understanding the RopeJoint and its MaxLength param?
ropeJoint not behaving how I expected.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
ropeJoint not behaving how I expected.
Last edited by zell2002 on Tue Jun 04, 2019 12:26 pm, edited 1 time in total.
Re: ropeJoint not behaving how I expected.
I don't know what your problem is, but it's working for me.
On the first few frames, the distance between the two bodies is adjusted to match the specified distance.
Code: Select all
local world = love.physics.newWorld(0, 10, false)
-- element 1 (free to fall) 1
local shape1 = love.physics.newRectangleShape(40, 30)
local body1 = love.physics.newBody(world, 400.5, 310.5, "dynamic")
local fix1 = love.physics.newFixture(body1, shape1)
-- element 2 (static)
local shape2 = love.physics.newRectangleShape(5, 5)
local body2 = love.physics.newBody(world, 390, 200, "static")
local fix2 = love.physics.newFixture(body2, shape2)
-- RopeJoint point relative to element 1
local x1, y1 = 5, 0
-- RopeJoint point relative to element 2
local x2, y2 = 0, 0
-- newRopeJoint needs them in world coordinates
local x1w, y1w = body1:getWorldPoints(x1, y1)
local x2w, y2w = body2:getWorldPoints(x2, y2)
-- Allow us to pause and skip frame by frame
local paused = true
-- Create the joint
local joint = love.physics.newRopeJoint(body1, body2,
x1w, y1w, x2w, y2w, 30, false)
function love.update(dt)
if not paused then
world:update(dt)
end
end
function love.draw()
-- Draw cyan rectangle for element1
love.graphics.setColor(0, 1, 1)
love.graphics.polygon("line", body1:getWorldPoints(shape1:getPoints()))
-- Draw green rectangle for element2
love.graphics.setColor(0, 1, 0)
love.graphics.polygon("line", body2:getWorldPoints(shape2:getPoints()))
-- Draw white line for RopeJoint
love.graphics.setColor(1, 1, 1)
x1w, y1w = body1:getWorldPoints(x1, y1)
x2w, y2w = body2:getWorldPoints(x2, y2)
love.graphics.line(x1w, y1w, x2w, y2w)
-- Display distance
love.graphics.print(math.sqrt((x2w-x1w)^2+(y2w-y1w)^2))
end
function love.keypressed(k)
if k == "space" then
paused = true
world:update(1/60)
end
if k == "return" then
paused = false
end
if k == "escape" then
return love.event.quit()
end
end
Re: ropeJoint not behaving how I expected.
I've uploaded a video to help explain the odd behaviour im getting.
Re: ropeJoint not behaving how I expected.
Where are you placing the points of the RopeJoint? Sounds like you're placing both at the same spot. See my code, I place one at a point relative to body1 and the other one at a point attached to body2.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 50 guests