Why is this not working?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Why is this not working?

Post by ixjackinthebox »

Why is the physics not working in this (I am not good with love physics) please help

main

Code: Select all

require "Code/GameCode"
require "Levels/Level"
GameCode

Code: Select all

--PlayersHealth = 100

local Move = 2.2

function love.update(dt)
World:update(dt)
----------------------------------------------------------------------------------
--movement
----------------------------------------------------------------------------------
	--left
	if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
		Players_x = Players_x - Move
	end
	--right
	if love.keyboard.isDown("d") or love.keyboard.isDown("right")then
		Players_x = Players_x + Move
	end
	--up
	if love.keyboard.isDown("w") or love.keyboard.isDown("up")then
		Players_y = Players_y - Move
	end
	--down
	if love.keyboard.isDown("s") or love.keyboard.isDown("down")then
		Players_y = Players_y + Move
	end
-----------------------------------------------------------------------------------
--Health
-----------------------------------------------------------------------------------

end
Level

Code: Select all

Players_x = 76
Players_y = 118

function love.load()
	love.physics.setMeter( 4 )
	World = love.physics.newWorld( 0, 500, true)
	
-------------------------------------------------------------------------
	-- Player
	PlayerSprite = love.graphics.newImage ("Sprites/Player/Player.png")
	-- Player Physics
	PlayerB = love.physics.newBody( World, Players_x, Players_y, "dynamic")
	PlayerS = love.physics.newRectangleShape( 22, 34 )
	PlayerF = love.physics.newFixture( PlayerB, PlayerS, 1)
	-- Background
	Background = love.graphics.newImage("Sprites/Background.png")
-------------------------------------------------------------------------
	-- Physics
	
	floor1B = love.physics.newBody( World, 61, 152, "static")
	floor1S = love.physics.newRectangleShape( 300, 30)
	floor1F = love.physics.newFixture( floor1B, floor1S, 1)
	
	floor2B = love.physics.newBody( World, 435, 182, "static")
	floor2S = love.physics.newRectangleShape( 300, 30)
	floor2F = love.physics.newFixture( floor2B, floor2S, 1)
	
	groundB = love.physics.newBody( World, 0, 570, "static")
	groundS = love.physics.newRectangleShape( 800, 30)
	groundF = love.physics.newFixture( groundB, groundS, 1)
	
end

function love.draw()
	love.graphics.draw( Background, 0, 0)
	love.graphics.draw (PlayerSprite, Players_x, Players_y)
end
edit: uploaded love file
Attachments
Game1.love
(60.5 KiB) Downloaded 127 times
Last edited by ixjackinthebox on Fri Dec 07, 2012 3:03 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Why is this not working?

Post by Robin »

Could you please pack your project in a .love and upload it as an attachment? As the rules state, it is much easier for us to help you with a .love.
Help us help you: attach a .love.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Why is this not working?

Post by Boolsheet »

You don't see the results of the physics simulation because you don't use its results to draw the character. A very simple way to change that is to get the position of the player body and use it to draw the player image.

Code: Select all

love.graphics.draw (PlayerSprite, PlayerB:getX(), PlayerB:getY())
Now it still won't move much because you don't exert any forces on the player body. You can do something like this in your movement code, but that is just a very simple example again.

Code: Select all

PlayerB:applyLinearImpulse(50, 0) -- Pushes body to the right.
The wiki warns that love.physics may not be the best thing for a very simple platformer. I'm sure Box2D can be configured in some way to give you the results you want, but you'll need a very good understanding of how everything works.
Shallow indentations.
User avatar
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Re: Why is this not working?

Post by ixjackinthebox »

Thanks for that
I saw the warning but I am not trying to make a game just learn love.physics
User avatar
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Re: Why is this not working?

Post by ixjackinthebox »

Ok so I used Body:applyForce to try to make the player move but it does not seem to do anything.
Attachments
Game1.love
(60.54 KiB) Downloaded 128 times
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Why is this not working?

Post by Ellohir »

I fumbled a bit with the numbers and managed to make the guy move. I changed gravity from 500 to 10, and the force applied from 750 to 2000. He still didn't jump, though.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 52 guests