Hi!
I'm totally new to Love2d, I have programmed Lua a little in minecraft, and I have an issue:
I want to have a picture as an avatar, controlled with the arrow keys. But the script doesn't give any error messages, but I only get a brown version of my originally red avatar which is uncontrollable.
If you need any more info, please ask me!
Thanks a lot in advance,
-Echamiq
Need some help with jumping and physics!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Need some help with jumping and physics!
- Attachments
-
- player.love
- (1.5 KiB) Downloaded 142 times
Last edited by Echamiq on Fri Dec 28, 2012 10:34 am, edited 1 time in total.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: General LÖVE newbie needs help with moving his avatar
Hi,
I don't know much of love.physics. But hopefull, these pointers might help.
First, you created your world with a gravity. So keep in my that any new body you put into that world will tend to go down, due to gravity.
In player.lua, you defined a restitution coefficient of 0. So it implies that at start, the body goes down, and stands sticked to the ground. You might want to change that coefficient to 1 (for full restitution), or any other value lower than 1, maybe 0.9, depending on what you need.
Actually, you are handling the inputs correctly (adding forces to the body). The problem is in player_draw. Drawing the player pic at player.x, player.y won't display it at the correct position, as love physics doesn't act on these values, but on player.body. So you just have to change this line in player.lua
to
Hope this helps.
I don't know much of love.physics. But hopefull, these pointers might help.
First, you created your world with a gravity. So keep in my that any new body you put into that world will tend to go down, due to gravity.
In player.lua, you defined a restitution coefficient of 0. So it implies that at start, the body goes down, and stands sticked to the ground. You might want to change that coefficient to 1 (for full restitution), or any other value lower than 1, maybe 0.9, depending on what you need.
Actually, you are handling the inputs correctly (adding forces to the body). The problem is in player_draw. Drawing the player pic at player.x, player.y won't display it at the correct position, as love physics doesn't act on these values, but on player.body. So you just have to change this line in player.lua
Code: Select all
love.graphics.draw(player.pic, player.x, player.y)
Code: Select all
love.graphics.draw(player.pic, player.body:getX(), player.body:getY())
Re: General LÖVE newbie needs help with moving his avatar
Well... Only drew the avatar slightly lower, and it's still brown-colored... The part about physics only acting on bodies makes a lot of sense though.
Thanks so much for helping already, but I'm afraid I'm going to need some more...
-Echamiq
Thanks so much for helping already, but I'm afraid I'm going to need some more...
-Echamiq
Re: General LÖVE newbie needs help with moving his avatar
The current color can affect images too. Then the color is being set with love.graphics.setColor(72, 160, 14) in ground_draw is still used when the player is drawn. The simplest way to fix this is to change the color to white before drawing the player:
An alternative way is to change how the current color affects what's drawn with love.graphics.setColorMode.
Code: Select all
function player_draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(player.pic, player.x, player.y)
end
Re: General LÖVE newbie needs help with moving his avatar
remove dt and the player.y test to get it to move
the force 200*0.01666 = 3.3333 is too small for the body to move
the force 200*0.01666 = 3.3333 is too small for the body to move
Code: Select all
function player_move(dt)
if love.keyboard.isDown("right") then
player.body:applyForce(player.speed , 0)
elseif love.keyboard.isDown("left") then
player.body:applyForce((player.speed * -1, 0)
elseif love.keyboard.isDown("up") then
player.body:applyForce(0, (player.speed * -1)
end
end
Re: General LÖVE newbie needs help with moving his avatar
That makes a lot of sense, thanks a bunch!Santos wrote:The current color can affect images too. Then the color is being set with love.graphics.setColor(72, 160, 14) in ground_draw is still used when the player is drawn. The simplest way to fix this is to change the color to white before drawing the player:
An alternative way is to change how the current color affects what's drawn with love.graphics.setColorMode.Code: Select all
function player_draw() love.graphics.setColor(255, 255, 255) love.graphics.draw(player.pic, player.x, player.y) end
I hadn't thought of calculating that, I'll out in both the changes when I have time, I'm currently participating in a game-making marathon in my home city, and I'm using Löve, yay!Zeliarden wrote:remove dt and the player.y test to get it to move
the force 200*0.01666 = 3.3333 is too small for the body to move
Code: Select all
function player_move(dt) if love.keyboard.isDown("right") then player.body:applyForce(player.speed , 0) elseif love.keyboard.isDown("left") then player.body:applyForce((player.speed * -1, 0) elseif love.keyboard.isDown("up") then player.body:applyForce(0, (player.speed * -1) end end
Thanks already everyone for helping me, I'll give you some karma
-Echamiq
Edit: ..if I knew how to.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: General LÖVE newbie needs help with moving his avatar
Well, the Karma mod isn't actually available.
But, you can give us some cookies instead. Or bacon.
But, you can give us some cookies instead. Or bacon.
Re: General LÖVE newbie needs help with moving his avatar
Okay, that explains it.Roland_Yonaba wrote:Well, the Karma mod isn't actually available.
But, you can give us some cookies instead. Or bacon.
Roland_Yonana: +1 internetbaconcookie
Santos: +1 internetbaconcookie
Zeliarden: +1 internetbaconcookie
-Echamiq
Re: General LÖVE newbie needs help with moving his avatar
Yay, I can use physics a little! My character can now jump, and move. But I don't want him to be able to jump (alter his vertical velocity) when he is in mid-air. The way I tried to do that is by usingI now recieved the input for the y and x velocity, and in a weird way which I can't comprehend both have to be 0 to be able to jump. Is there a way for me to specify that I want the x-velocity to be maintained and the y-velocity to be changed to my jump-velocity?
More advanced questions, yay!
Thanks a bunch for helping me!
-Echamiq
Code: Select all
player.body:getLinearVelocity()
More advanced questions, yay!
Thanks a bunch for helping me!
-Echamiq
- Attachments
-
- loveq.love
- (1.64 KiB) Downloaded 117 times
Who is online
Users browsing this forum: No registered users and 3 guests