viewtopic.php?f=4&t=78736
Right now, I have three entities, the player, an enemy, and a "hitbox". I want to be able to check whether or not the player's hitbox collides with the enemy, but the hitbox acts like a physical, tangible object, which is something I don't want. Ideally, the hitbox should exist only when I hit the attack button (which it does), and NOT exert forces on the player, which it currently does (It's the red square). I want the hitbox to be more of an intangible object, or at the very least, not apply any forces on the player or enemy. Here's an example of what I currently have.
Base code for my objects is below.
Code: Select all
--physics engine below
love.physics.setMeter(64)
world = love.physics.newWorld(0, 200, true)
world:setCallbacks(beginContact, endContact, preSolve, postSolve)
text = ""
persisting = 0
player = {}
player.b = love.physics.newBody(world, 400, 200, "dynamic")
player.b:setMass(10)
player.s = love.physics.newRectangleShape(32,54)
player.f = love.physics.newFixture(player.b, player.s)
player.f:setRestitution(0.4)
player.f:setUserData("Knight")
player.x = 50;
player.y = 50;
enemy = {}
enemy.b = love.physics.newBody(world, 300, 200, "dynamic")
enemy.b:setMass(10)
enemy.s = love.physics.newCircleShape(20)
enemy.f = love.physics.newFixture(enemy.b, enemy.s)
enemy.f:setRestitution(0.4)
enemy.f:setUserData("Enemy")
static = {}
static.b = love.physics.newBody(world, 325, 600, "static")
static.s = love.physics.newRectangleShape(650,1)
static.f = love.physics.newFixture(static.b, static.s)
static.f:setUserData("Floor")
swordhitbox = {}
swordhitbox.b = love.physics.newBody(world, 10000, 10000, "static")
swordhitbox.s = love.physics.newRectangleShape(25,25)
swordhitbox.f = love.physics.newFixture(swordhitbox.b, swordhitbox.s)
swordhitbox.f:setUserData("swordhitbox")
swordhitbox.f:setSensor(playerhitboxsensor)