Hello, well, I've got an idea for a game so I'm going to try to make it
I have come across a problem though, relating to the physics.
You can say the game is sort of 'top-down' view, so I don't need gravity.
There are two 'circles' controlled by players.
I want each dot to have a continuous forward velocity, that velocity doesn't change. However, the player can change the angle of the velocity by pressing left/right arrow keys.
How can I code this angle change?
I've tried experimenting, and setAngle doesn't change anything. setSpin affects the angle after a collision, but nothing affecting the direction of velocity itself.
I have a feeling it might have to do with 'impulse', force or 'torque'. I don't know what they are
Using physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Using physics
Code: Select all
angle = 0
turn_speed = 0.05
speed = 1
function update( dt )
velx = math.sin(angle) * speed
vely = math.cos(angle) * speed
player:applyImpulse(velx, vely)
end
function keypressed( key )
if key == love.key_right then
angle = angle + turn_speed
elseif key == love.key_left then
angle = angle - turn_speed
end
end
Re: Using physics
Thanks Kaze, that works great!
However, I have a problem:
When you press left/right, the object doesn't respond immediately, instead it takes a while for it to turn around because it still needs to overcome the force in its current direction.
How can I make it so that it will immediately turn without needing to slow down first?
However, I have a problem:
When you press left/right, the object doesn't respond immediately, instead it takes a while for it to turn around because it still needs to overcome the force in its current direction.
How can I make it so that it will immediately turn without needing to slow down first?
Re: Using physics
Use setVelocity instead of applyImpulseZeggy wrote:Thanks Kaze, that works great!
However, I have a problem:
When you press left/right, the object doesn't respond immediately, instead it takes a while for it to turn around because it still needs to overcome the force in its current direction.
How can I make it so that it will immediately turn without needing to slow down first?
Re: Using physics
Hehe, I used that, except strange things happen when there's a collision between to objects. Ie. they don't collide (properly).
What I'd like is to have the same acceleration like when impulse is used, except when turning, no velocity is lost.
Other than that, the objects can still slow down when colliding into something, maybe even move backwards from the force. But eventually the constant acceleration will make them continue moving again.
What I'd like is to have the same acceleration like when impulse is used, except when turning, no velocity is lost.
Other than that, the objects can still slow down when colliding into something, maybe even move backwards from the force. But eventually the constant acceleration will make them continue moving again.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests