What method is the best to make a character, and have a camera?
I tried to use applyForce to the character body, but I need a way to make it come to a stop immediately after he stops hitting the arrow keys.
I also need a way to stop it from gaining speed as you hold it.
I tried using setPosition but then the physics are like canceled out on that block.
What should I do?
Making a character walk with physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 11
- Joined: Tue Jun 05, 2012 8:27 pm
Re: Making a character walk with physics
It depends, do you really need realistic physics? If the answer is "Yes, I absolutely need realistic physics" then you can use Body:setLinearVelocity; if you're just making a platformer, Box2d might be too much (too heavy, too complicated) and coding simple platformer physics isn't too hard
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Prole
- Posts: 11
- Joined: Tue Jun 05, 2012 8:27 pm
Re: Making a character walk with physics
Yes, I kind of do because the player can dig, and would have to fall and stuff to get deeper.
Re: Making a character walk with physics
Well, that still might not be too hard to code; furthermore, digging requires destroying and rebuilding shapes each frame during which you dig (if you dig continuously), it may actually be harder than coding your simplified physics system that only has the features you need
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Making a character walk with physics
Re: Making a character walk with physics
If your character needs to stop moving immediately, you're probably not using realistic physics which means you probably don't need love.physics for it. I think you'd indeed be better off programming your own simple physics system.I tried to use applyForce to the character body, but I need a way to make it come to a stop immediately after he stops hitting the arrow keys.
Re: Making a character walk with physics
If you want, you can just use getX() and setX().
As for everyone else in the thread who decided not to directly answer the question; I've been in this situation before, where I needed to use love.physics for accurate physics that could not be achieved through a library, but I needed player movement that did not feel like I was on ice.
You could also use the combination of :applyForce() and :setLinearDamping(), where higher linear damping values will make the player stop quicker after the force is applied.
Code: Select all
local x = body:getX()
if love.keyboard.isDown('left') then
body:setX(x - 400 * dt)
elseif love.keyboard.isDown('right') then
body:setX(x + 400 * dt)
end
You could also use the combination of :applyForce() and :setLinearDamping(), where higher linear damping values will make the player stop quicker after the force is applied.
Re: Making a character walk with physics
Fisrt, he said he already tried setPosition; second, I addressed the question directly telling him that he can use setLinearVelocity on the body.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Making a character walk with physics
Admittedly, I missed the part about him already trying position setting, but linear damping and applyForce is a valid solution. With the right numbers, it provides much smoother movement than setting linear velocity, and is much easier to implement.
When I referred to people who did not answer the question, that was not directed at you. Sorry for any confusion.
When I referred to people who did not answer the question, that was not directed at you. Sorry for any confusion.
Who is online
Users browsing this forum: No registered users and 3 guests