I want to create a swing traps like pendulum in platformer games. But can't code properly?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
I want to create a swing traps like pendulum in platformer games. But can't code properly?
My platformer games require a spikeball hanging from chain and swinging like pendulum. But, I'm no able to code it properly, specially the collision part. Though I able to animate like pendulum but the collision body still stays in its original position. Can anyone help me in this matter?
Re: I want to create a swing traps like pendulum in platformer games. But can't code properly?
I shouldn't have but it kept me busy coding a bit, something like that?
If this is the case for collisions you can use Kikito's bump library, but as you also want some "physical" effects you can use love.physics with or a higher level API like windfield (there is probably newer and better than winfield).
You can go to the Awesome Löve2d Github page, you will find what you are looking for there, there is no point in recreating the wheel unless you are doing it to learn, in which case there is probably plenty of documentation for what you want to do
Edit: next time please share a code snippet, it would help us understand what you want to do or see where you are wrong
If this is the case for collisions you can use Kikito's bump library, but as you also want some "physical" effects you can use love.physics with or a higher level API like windfield (there is probably newer and better than winfield).
You can go to the Awesome Löve2d Github page, you will find what you are looking for there, there is no point in recreating the wheel unless you are doing it to learn, in which case there is probably plenty of documentation for what you want to do
Edit: next time please share a code snippet, it would help us understand what you want to do or see where you are wrong
- Attachments
-
- main.lua
- I did not integrate the collisions there for lack of time but I told you how to do it simply.
- (2.45 KiB) Downloaded 63 times
Re: I want to create a swing traps like pendulum in platformer games. But can't code properly?
Love2D needs to you to update the physical body using whatever motion (pendulum) and then the drawing operation is a different thing and you want them to of course line up on the screen.
It sounds like you're updating the drawing without physically moving the object so look into that if you haven't already.
@bigfoot your gif cycle above runs too long and triggers me.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: I want to create a swing traps like pendulum in platformer games. But can't code properly?
I'm thinking about it thanks to what togFox said and by rereading your post (which I had misinterpreted a little by the way) if you already use love.physics think about updating the world!
@togFox sorry, my will was not to hypnotize you
Code: Select all
world = love.physics.newWorld( 0,0 )
function love.update(dt)
world:update(dt)
end
Re: I want to create a swing traps like pendulum in platformer games. But can't code properly?
Something like this? (space bar to release)
Code: Select all
local lp = love.physics
local lg = love.graphics
local world = lp.newWorld(0, 100)
local function newObject(body, shape)
return {body = body, shape = shape, fixture = lp.newFixture(body, shape)}
end
local anchor = newObject(lp.newBody(world, 400, 250, "static"),
lp.newRectangleShape(10, 10))
local ball = newObject(lp.newBody(world, 550, 250, "static"),
lp.newCircleShape(10))
local joint = lp.newRopeJoint(anchor.body, ball.body, anchor.body:getX(),
anchor.body:getY(), ball.body:getX(), ball.body:getY(), 150)
local platform = newObject(lp.newBody(world, 400, 435, "static"),
lp.newRectangleShape(700, 10))
local object = newObject(lp.newBody(world, 400, 420, "dynamic"),
lp.newRectangleShape(20, 30))
object.body:setMass(0.1)
function love.keypressed(k)
if k == "escape" then return love.event.quit() end
if k == "space" then ball.body:setType("dynamic") end
end
function love.update(dt)
world:update(dt)
end
function love.draw()
lg.polygon("fill", anchor.body:getWorldPoints(anchor.shape:getPoints()))
lg.circle("fill", ball.body:getX(), ball.body:getY(), ball.shape:getRadius())
lg.line(anchor.body:getX(), anchor.body:getY(), ball.body:getX(),
ball.body:getY())
lg.polygon("fill", platform.body:getWorldPoints(platform.shape:getPoints()))
lg.polygon("line", object.body:getWorldPoints(object.shape:getPoints()))
end
Who is online
Users browsing this forum: Google [Bot] and 5 guests