Hello everyone, when I first made my game Aedifico I was asked by a couple people how I got the player to move with the feet. At first I was using a method of averaging all the body parts and applying a force between them which worked nicely, although it had drawbacks in some scenarios. Now I’ve decided to only average the feet and apply a force between the feet and body, this seems to give a less fluid look but is overall more stable. Here is a video of the most recent update before I started the player class revision: http://www.youtube.com/watch?v=XudkW-h6QCI
The end of this video acts as a testimony to the fact that even after a year of work, a bug can pop out that hints to no direction or cause. That was a reason why I decided to revise the player, another reason is if you have code that is say 3 months + old you may not need to change it but if you do you’re going to come out with something better than before. The point is you can never run out of things to change or ideas to learn about.
There are still many tweaks to be made and a tiny bug which makes the left foot act differently to the right foot, despite the code being identical (as far as I have checked). I’ve tried to make the implementation quite straight forward.
--To initialise the player use this function in setup()
plyvar = Player(x,y,joystick position,joystick diameter)
--For touch handling create table 'tchs' in setup() and paste the following in touched()
if t.state == BEGAN then
local jpos,jsize = ply.joypos,ply.joysize
local epos,esize = ply.epos,ply.esize
if vec2(t.x,t.y):dist(jpos) < jsize/2 then
table.insert(tchs,{t,ply,"ply"})
elseif vec2(t.x,t.y):dist(epos) < esize/2 then
table.insert(tchs,{t,ply,"jump"})
else
table.insert(tchs,{t,ply,"look"})
end
end
for k,v in pairs(tchs) do
if t.id == v[1].id then
tchs[k][1] = t
tchs[k][2]:touched(tchs[k])
if v[1].state == ENDED then
tchs[k] = nil
end
end
end
--Draw the player by putting ply:draw() and ply:drawJoystick() in draw()
--Any body you use as the ground should have the categories {0,2}
--Use the code however you like
Code:
http://pastebin.com/PwHKNH9G
I’m planning on making a similar designed enemy which uses AI to get around which should be interesting. Any feedback on the code itself or the player ‘engine’ is more than welcome. Hope you enjoy it