hi, i have a problem regarding bullets and costume changing in my game.
so, in my game if you press any of the arrow keys while not moving then the player switches costume and the bullet flies in that direction. But, if your moving.for example if you hold left and you press the right arrow to shoot right, the bullet comes out of his back because the costume hasnt changed.
if thats confusing here is my .love file so see for yourself
please help
Costume and Bullet Help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Costume and Bullet Help
- Attachments
-
- game.love
- (59.68 KiB) Downloaded 141 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Costume and Bullet Help
So what do you want to happen?
Should the wizard keep going if he is running north and then fires south? Or should he stop to shoot the bullet?
For how long should he stop? And if not stopping, how long should the animation stay in he "south" position, with the wizard backwards before turning back to the "north" position again?
The answer of your question depends on the answers to those questions. (The important part of "how long" is whether you want it to be a frame or x seconds, so you don't have to know the exact number of milliseconds. )
Should the wizard keep going if he is running north and then fires south? Or should he stop to shoot the bullet?
For how long should he stop? And if not stopping, how long should the animation stay in he "south" position, with the wizard backwards before turning back to the "north" position again?
The answer of your question depends on the answers to those questions. (The important part of "how long" is whether you want it to be a frame or x seconds, so you don't have to know the exact number of milliseconds. )
Help us help you: attach a .love.
Re: Costume and Bullet Help
i just want it to keep moving the same direction but just switch costume to the direction of the arrow key then switch back tothe original costume
Re: Costume and Bullet Help
Hello, made a few changes to what you already had to get this to work, the new .love is attached and the changes are below.
lastShot is the time since the player last fired.
changeTime is how long the player will stay with the costume of shooting in the last direction if they stop shooting.
lastShot is set to zero when the player shoots and their costume is changed to be facing that direction.
lastShot has delta time added to it until it is greater than changeTime.
The players costume can only be changed by walking if lastShot is greater than changeTime.
Code: Select all
local lastShot = 1
local changeTime = 1
function player.update(dt)
-- stuff
if(lastShot <= changeTime) then
lastShot = lastShot + dt
end
end
function love.keypressed(key) -- Instead of love.keyreleased(key)
--stuff
end
function player.animreset(key)
if(lastShot > changeTime) then
-- stuff
end
end
function player.shoot(key)
-- stuff
if(key == "up" or key == "down" or key == "left" or key == "right") then
lastShot = 0
end
end
changeTime is how long the player will stay with the costume of shooting in the last direction if they stop shooting.
lastShot is set to zero when the player shoots and their costume is changed to be facing that direction.
lastShot has delta time added to it until it is greater than changeTime.
The players costume can only be changed by walking if lastShot is greater than changeTime.
- Attachments
-
- NewGame.love
- (59.12 KiB) Downloaded 149 times
Re: Costume and Bullet Help
thank you so much, but is there a way for it to wait half a second then switch back to the original costume?
thanks
thanks
Re: Costume and Bullet Help
Indeed, change "local changeTime = 1" to "local changeTime = 0.5"
Re: Costume and Bullet Help
The way the bullets fly is not physically correct by the way, while walking left and shooting down the bullets should still fly left.
If you want physically correct, that is.
If you want physically correct, that is.
Re: Costume and Bullet Help
the costume changing isnt really working.
im holding down "d" and i then press right arrow. i switch costume but then i stay in the switched costume (while still holding "d")
im holding down "d" and i then press right arrow. i switch costume but then i stay in the switched costume (while still holding "d")
Re: Costume and Bullet Help
I got your back
Moved the player.animreset(key) stuff to be in player.update(dt)
Moved the player.animreset(key) stuff to be in player.update(dt)
- Attachments
-
- NewNewGame.love
- (59.11 KiB) Downloaded 125 times
Re: Costume and Bullet Help
I would like tothank every1 who helped me.
THANKS!!!!
THANKS!!!!
Who is online
Users browsing this forum: Google [Bot] and 13 guests