Hello everyone
What I'm trying to do is a game, visible from upper side. It will be curling-like game with sliding balls.
I don't need gravity but collision detection and friction is needed.
For example I throw a ball and it slides on rough surface (all seen from upper side). I want this ball to stop, because of surface roughness. Is there a simple way to do that with love?
PS: I tried to use sensors but it is complicated solution (collision detection, setting velocity manually, etc...). I need something more simple.
from bubor with love
ground friction
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: ground friction
I've done stuff similar to this before. Each "ball" should have four variables representing it for the x position, y position, x velocity, and y velocity. I usually just use x, y, xvel, and yvel. (You could use x position, y position, direction, and velocity but working with trig is annoying.)
X and y keep track of the position, while xvel and yvel keep track of how fast the object is moving, or how much x and y change each frame. If xvel and yvel never change, then your object will keep moving in the same direction. But, if you want to add friction, all you need to do is multiply the velocities by a number smaller than one. The lower the number, the higher the friction.
If you have any more questions, just ask.
Here is an example script:
X and y keep track of the position, while xvel and yvel keep track of how fast the object is moving, or how much x and y change each frame. If xvel and yvel never change, then your object will keep moving in the same direction. But, if you want to add friction, all you need to do is multiply the velocities by a number smaller than one. The lower the number, the higher the friction.
If you have any more questions, just ask.
Here is an example script:
Code: Select all
function love.load()
x = 100
y = 100
xvel = 6
yvel = 6
friction = .98 --Try chaning this to see how different numbers affect the speed of the object. Note: if this is above 1, the object will speed up!
end
function love.update()
--Applying friction to the velocities:
xvel = xvel * friction
yvel = yvel * friction
--Changing the position by the velocities:
x = x + xvel
y = y + yvel
end
function love.draw()
--Drawing the object:
love.graphics.circle("line", x, y, 10, 20)
end
Re: ground friction
OH! I forgot about collision detection! I'll write something up! Be right back...
EDIT: I never did get around to doing that... I will eventually...
EDIT: I never did get around to doing that... I will eventually...
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests