Odd way for a physics engine to work but you can just set velocity to 0 or do as skofo suggested, but that's how damping works. What do you use for propelling the craft?lbhoward wrote:It appears Damping needs a value between 0.0 and 1.0 and it seems to sort of apply a 'slow brake' effect, where it's speed decreases slightly. By declaring that 'player:setDamping(0.5)' on load - we get a nice 'decrease in speed' but by the time my ship comes to a hault it's already at the otherside of the map.
When I put it to 0.7 - it just refuses to move - 0.6 is the maximum it seems to take and even that causes it to drift to the other side of the map - perhaps Damping isn't the answer =/
Is there anyone out there who succesfully implemented a keypressed feature where on release the velocity resets perfectly and their ship comes to a standstill.
newBody() *EDIT* And Collisions! *EDIT* And destroy()!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 215
- Joined: Sun Jan 18, 2009 8:03 pm
Re: newBody() *EDIT* And Collisions!
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Re: newBody() *EDIT* And Collisions!
I use setVelocity to propel the craft, and when I call for setVelocity(0, 0) when the left/right key is released - the ship just carries on at the same speed.
-
- Party member
- Posts: 215
- Joined: Sun Jan 18, 2009 8:03 pm
Re: newBody() *EDIT* And Collisions!
Impossible. Something else must be changing the velocity after that. Try disabling all other places changing velocity or applying impulses or forces. Make sure that the setting of the velocity from having the keys down cannot be applied after the setting of the velocity to 0.lbhoward wrote:I use setVelocity to propel the craft, and when I call for setVelocity(0, 0) when the left/right key is released - the ship just carries on at the same speed.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Re: newBody() *EDIT* And Collisions!
This is all that is going on to effect the Velocity/Impulse - nowhere else in the code makes reference to the movement. No matter what it drifts off into space at the same speed.
Bah! And now collisions errors - LOVE's physics system utterly confuses this programmer O.o
Vexxer_one is the 'String' or so I understand.
vexxer_one is the body.
vexxer_one_box is the hitbox (shape attached to the body) yet when I collide into it (the collision is recognized) but the 'Vexxer' just stays there. Am I doing something wrong (Ha, I'm doing everything wrong today!)
Code: Select all
function keypressed(key)
if key == love.key_left and level_one == 1 then
player:applyImpulse(-5000, 0)
player:setVelocity(-5000, 0)
end
if key == love.key_right and level_one == 1 then
player:applyImpulse(5000, 0)
player:setVelocity(5000, 0)
end
end
function keyreleased(key)
if key == love.key_left and level_one == 1 then
player:applyImpulse(0, 0)
player:setVelocity(0, 0)
end
if key == love.key_right and level_one == 1 then
player:applyImpulse(0, 0)
player:setVelocity(0, 0)
end
end
Bah! And now collisions errors - LOVE's physics system utterly confuses this programmer O.o
Code: Select all
function collision(a, b, c)
local f, r = c:getFriction(), c:getRestitution()
local s = c:getSeparation()
local px, py = c:getPosition()
local vx, vy = c:getVelocity()
local nx, ny = c:getNormal()
text = "Last Collision:\n"
text = text .. "Shapes: " .. a .. " and " .. b .. "\n"
text = text .. "Position: " .. px .. "," .. py .. "\n"
text = text .. "Velocity: " .. vx .. "," .. vy .. "\n"
text = text .. "Normal: " .. nx .. "," .. ny .. "\n"
text = text .. "Friction: " .. f .. "\n"
text = text .. "Restitution: " .. r .. "\n"
text = text .. "Separation: " .. s .. "\n"
if a == Player and b == Vexxer_one then
Vexxer_one:destroy()
vexxer_one:destroy()
vexxer_one_box:destroy()
end
end
vexxer_one is the body.
vexxer_one_box is the hitbox (shape attached to the body) yet when I collide into it (the collision is recognized) but the 'Vexxer' just stays there. Am I doing something wrong (Ha, I'm doing everything wrong today!)
Re: newBody() *EDIT* And Collisions!
It might be easier if you posted a LOVE file.
Re: newBody() *EDIT* And Collisions!
*EDIT* Linky to the file loaded up onto my Filefront http://files.filefront.com/starfoxlove/ ... einfo.html
Sorry it took so long to post this... I sort of... erm *hides*
Made it all case insensitive. Yup had to go through and replace every filename, all fixed and here is the file! Hope it helps - just hit ENTER on Start Game and you can use LEFT/RIGHT to move - SPACE just fires a harmless graphic up into the air which un-draws when it reaches the top.
I am very much unsure of how exactly to destroy the 'b' object (should be the enemy) on a collision - and to reduce lets say - a variable 'player_health' by say 10 on a collision with an enemy. In fact I am very much confused about the whole physics system. This is my first time working with any kind of real physics - I'm used to coding emulated stuff like. 'If player_x >= enemy_x + 30 and player_x <= enemy_x -30' creating sort of 'emulated' hit boxes, infact I may just give up on physics alltogether and do it this way >.<
Sorry it took so long to post this... I sort of... erm *hides*
Made it all case insensitive. Yup had to go through and replace every filename, all fixed and here is the file! Hope it helps - just hit ENTER on Start Game and you can use LEFT/RIGHT to move - SPACE just fires a harmless graphic up into the air which un-draws when it reaches the top.
I am very much unsure of how exactly to destroy the 'b' object (should be the enemy) on a collision - and to reduce lets say - a variable 'player_health' by say 10 on a collision with an enemy. In fact I am very much confused about the whole physics system. This is my first time working with any kind of real physics - I'm used to coding emulated stuff like. 'If player_x >= enemy_x + 30 and player_x <= enemy_x -30' creating sort of 'emulated' hit boxes, infact I may just give up on physics alltogether and do it this way >.<
Re: newBody() *EDIT* And Collisions!
I feex et!
I removed setVelocity/applyImpulse and replaced it with applyForce, then removed the keypress/keyrelease functions and replaced em with a keydown check in the update function so it continuously applies the force when a key is down, as opposed to doing it only once when a key is pressed a la the keypress function. You can change the numbers in applyForce to adjust the speed and change the number in setDamping to adjust the friction.
Have fun!
P.S. Neato game! : Looks like you already did a buncha work on it. Nice job!
I removed setVelocity/applyImpulse and replaced it with applyForce, then removed the keypress/keyrelease functions and replaced em with a keydown check in the update function so it continuously applies the force when a key is down, as opposed to doing it only once when a key is pressed a la the keypress function. You can change the numbers in applyForce to adjust the speed and change the number in setDamping to adjust the friction.
Have fun!
P.S. Neato game! : Looks like you already did a buncha work on it. Nice job!
Re: newBody() *EDIT* And Collisions!
Amazing! Thank you very much for the support you have given with this issue. I am always very cautious what I put in Update - as I once put a love.audio.play in there and it tried playing 1 instance of the sound every update >.< All I need to do now is get collisions to destroy 'b' and I can start building the level.
Thanks to everyone for their assistance!
And on one final note to this thread - if someone could give a very basic example of the destroy function it would be much appreciated.
I initiate vexxer_one the body.
I initiate vexxer_one_box the shape, with a setData of Vexxer_one .
I use a callback of collision(a, b ,c).
How do I use an if statement so that 'if something collides with vexxer_one_box - blow it up' my 'if b == Vexxer_one' doesn't seem to want to work - am I doing something wrong here =P I've tried 'if b == vexxer_one_box' too.
*EDIT* I've made a bit of progress with the destroy function - I call
And in update(dt)
My only problem is I get a 'Attempt to index global' error. >.< This is the last aspect of LOVE I do not fully understand, so anyone who fills me in the correct usage gets a cookie and my LOVE
Thanks to everyone for their assistance!
And on one final note to this thread - if someone could give a very basic example of the destroy function it would be much appreciated.
I initiate vexxer_one the body.
I initiate vexxer_one_box the shape, with a setData of Vexxer_one .
I use a callback of collision(a, b ,c).
How do I use an if statement so that 'if something collides with vexxer_one_box - blow it up' my 'if b == Vexxer_one' doesn't seem to want to work - am I doing something wrong here =P I've tried 'if b == vexxer_one_box' too.
*EDIT* I've made a bit of progress with the destroy function - I call
Code: Select all
function collision(a, b, c)
local f, r = c:getFriction(), c:getRestitution()
local s = c:getSeparation()
local px, py = c:getPosition()
local vx, vy = c:getVelocity()
local nx, ny = c:getNormal()
bCollided = b
aCollided = a
text = "Last Collision:\n"
text = text .. "Shapes: " .. a .. " and " .. b .. "\n"
text = text .. "Position: " .. px .. "," .. py .. "\n"
text = text .. "Velocity: " .. vx .. "," .. vy .. "\n"
text = text .. "Normal: " .. nx .. "," .. ny .. "\n"
text = text .. "Friction: " .. f .. "\n"
text = text .. "Restitution: " .. r .. "\n"
text = text .. "Separation: " .. s .. "\n"
end
Code: Select all
if bCollided == 'Vexxer_one' and aCollided == 'Player' then
Vexxer_one:destroy()
vexxer_one:destroy()
vexxer_one_box:destroy()
end
Who is online
Users browsing this forum: Bing [Bot] and 1 guest