I've searched on the forums and didn't manage to find an answer to this question and I apologize if I missed it.
I feel that this question does not require a .love file to be answered.
Basically I have a rectangular body that is moved with applyForce and when it moves it rotates but I want it to just slide. I need to know how to stop the body from rotating entirely.
Make a body slide instead of rotate.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
Make a body slide instead of rotate.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
Re: Make a body slide instead of rotate.
Now I creating game with love.physics (and every part of physics interesting for me too), and may be this http://love2d.org/wiki/Body:setFixedRotation?
Last edited by Snuux on Tue Jul 29, 2014 9:53 am, edited 1 time in total.
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
- Dr.Tyler O.
- Citizen
- Posts: 58
- Joined: Tue Jul 29, 2014 9:17 am
- Location: United States
Re: Make a body slide instead of rotate.
Thanks!Snuux wrote:Now I creating game with love.physics, and may be this http://love2d.org/wiki/Body:setFixedRotation?
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
Re: Make a body slide instead of rotate.
I try to applyForce for Rectangle shape, but it don't rotate! What I do wrong?
Code: Select all
function createRectangle(x, y, w, h)
local o = {}
o.b = love.physics.newBody(world, x, y, "dynamic")
o.s = love.physics.newRectangleShape(0, 0, w, h)
o.f = love.physics.newFixture(o.b, o.s)
return o
end
function love.load()
world = love.physics.newWorld(0, 0)
object = createRectangle(260, 260, 100, 100)
end
function love.update(dt)
world:update(dt)
object.b:applyForce(1000, 1500)
end
function love.draw()
debugWorldDraw(world)
end
-----------DEBUG
function debugWorldDraw(world)
local bodies = world:getBodyList()
for b=#bodies,1,-1 do
local body = bodies[b]
local bx,by = body:getPosition()
local bodyAngle = body:getAngle()
love.graphics.push()
love.graphics.translate(bx,by)
love.graphics.rotate(bodyAngle)
math.randomseed(1) --for color generation
local fixtures = body:getFixtureList()
for i=1,#fixtures do
local fixture = fixtures[i]
local shape = fixture:getShape()
local shapeType = shape:getType()
local isSensor = fixture:isSensor()
if (isSensor) then
love.graphics.setColor(0,0,255,96)
else
love.graphics.setColor(math.random(32,200),math.random(32,200),math.random(32,200),96)
end
love.graphics.setLineWidth(1)
if (shapeType == "circle") then
local x,y = fixture:getMassData() --0.9.0 missing circleshape:getPoint()
local x,y = shape:getPoint() --0.9.1
local radius = shape:getRadius()
love.graphics.circle("fill",x,y,radius,15)
love.graphics.setColor(0,0,0,255)
love.graphics.circle("line",x,y,radius,15)
local eyeRadius = radius/4
love.graphics.setColor(0,0,0,255)
love.graphics.circle("fill",x+radius-eyeRadius,y,eyeRadius,10)
elseif (shapeType == "polygon") then
local points = {shape:getPoints()}
love.graphics.polygon("fill",points)
love.graphics.setColor(0,0,0,255)
love.graphics.polygon("line",points)
elseif (shapeType == "edge") then
love.graphics.setColor(0,0,0,255)
love.graphics.line(shape:getPoints())
elseif (shapeType == "chain") then
love.graphics.setColor(0,0,0,255)
love.graphics.line(shape:getPoints())
end
end
love.graphics.pop()
end
local joints = world:getJointList()
for index,joint in pairs(joints) do
love.graphics.setColor(0,255,0,255)
local x1,y1,x2,y2 = joint:getAnchors()
if (x1 and x2) then
love.graphics.setLineWidth(3)
love.graphics.line(x1,y1,x2,y2)
else
love.graphics.setPointSize(3)
if (x1) then
love.graphics.point(x1,y1)
end
if (x2) then
love.graphics.point(x2,y2)
end
end
end
local contacts = world:getContactList()
for i=1,#contacts do
love.graphics.setColor(255,0,0,255)
love.graphics.setPointSize(3)
local x1,y1,x2,y2 = contacts[i]:getPositions()
if (x1) then
love.graphics.point(x1,y1)
end
if (x2) then
love.graphics.point(x2,y2)
end
end
end
- Attachments
-
- Small Experiment.love
- Press space for pause and resume rotation
- (1.1 KiB) Downloaded 116 times
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
- Drop of light LD#30
- OUTRANGE LD#31
(Sorry for my english. I learn it myself, and I don't have enough experience)
Re: Make a body slide instead of rotate.
ApplyForce by default pushes against the center of mass. Unless there's something else that should force the object to rotate, it won't, because the force is distributed evenly against the object.
If you send two more arguments for the x and y coordinates inside the object that you want to push against, it should start rotating.
If you send two more arguments for the x and y coordinates inside the object that you want to push against, it should start rotating.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests