Hey Gang!
I'm trying to make a little fighting game and I'm very happy with what I have right now.
The problem is that if I attack the enemy from the left side and he is looking left, the knockback won't work.
It works fine from the right side and from both sides if the enemy is looking right.
Maybe someone has time to look over my code. I tried to keep it as simple as I can.
The green character is controled by the left and right arrow keys and "x" for jumping und "c" for attacking.
If something else is wrong with the code, please feel free to tell me.
Thank you guys and greetings from Berlin
- Alex
Enemy Knockback Problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Enemy Knockback Problem
- Attachments
-
- minifight.zip
- Mini Fight
- (192.69 KiB) Downloaded 102 times
Re: Enemy Knockback Problem
I think I fixed your bug . In player.lua the mapColl function, you had this;
Fixed code in player.lua
The elseif self.dir == "right" was unnecessary, you only needed to check if the player had a non-zero xval property. I must say I enjoyed punching the red dino for way too long .
Code: Select all
-- LEFT/RIGHT COLLISION
if self.xvel < 0 then
if not tileCollision(map,self,"left") then
self.x = self.newX
else
self.x = self.newX + map.tilesize - (self.newX % map.tilesize)
self.xvel = 0
end
elseif self.dir == "right" then
if not tileCollision(map,self,"right") then
self.x = self.newX
else
self.x = self.newX - ((self.newX + self.w) % map.tilesize)
self.xvel = 0
end
end
Code: Select all
if self.xvel < 0 then
if not tileCollision(map,self,"left") then
self.x = self.newX
else
self.x = self.newX + map.tilesize - (self.newX % map.tilesize)
self.xvel = 0
end
elseif self.xvel > 0 then
if not tileCollision(map,self,"right") then
self.x = self.newX
else
self.x = self.newX - ((self.newX + self.w) % map.tilesize)
self.xvel = 0
end
end
Re: Enemy Knockback Problem
Thanks man!
Remember: before you recycle your old code, check it for the new purpose!
I try to keep you updated on this project.
-- Alex
Remember: before you recycle your old code, check it for the new purpose!
I try to keep you updated on this project.
-- Alex
Who is online
Users browsing this forum: Bing [Bot] and 0 guests