Need help applying Physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 6
- Joined: Wed Feb 10, 2016 5:05 am
- Location: Conway, South Carolina
- Contact:
Need help applying Physics
So I have been relearning LUA and the LOVE engine here recently, and I have been making small little games. I have been looking into adding some physics (where I jump and then fall back down towards the ground, friction, and so forth), I have looked up some tutorials, looked at some other projects, and so much, but can never figure this out. Can I get a little help?
- Attachments
-
- Game.love
- (64.19 KiB) Downloaded 115 times
Re: Need help applying Physics
Take a look at Bump, viewtopic.php?f=5&t=79223
Its a nice collision detection library.
Its a nice collision detection library.
-
- Prole
- Posts: 6
- Joined: Wed Feb 10, 2016 5:05 am
- Location: Conway, South Carolina
- Contact:
Re: Need help applying Physics
I want to know how to do this without using libraries just so I get a learning experience. Is there any tutorial for this?sefan wrote:Take a look at Bump, viewtopic.php?f=5&t=79223
Its a nice collision detection library.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Need help applying Physics
Bump isn't physics BTW. It's just collision detection. I would say that as long as you understand aabb you could just experiment until you get the feel you want or reach a specific problem. Physics in games is something you design around your game. I'm assuming you know how to move things on the screen and if you Google "kinetic physics forumlas" you should be able to design something to fit your needs yourself. It's the best way to learn. Because then you can apply that to anything.
Edit: now that I am on my pc i can expand a bit. in physics to determine ones displacement there is this formula.
There is 2 approaches presented here that you can take you can use vectors (a magnitude and angle) or indivual components. Its easier to use components. now we just have to plug in information to make it relevant for our game.
Now this is a very simple example. If you add collision then you will have working physics. Basically the more you want the more you do. If you want friction and mass then google the formula for them and how they effect things. As you go through and implement each formula your game will end up with more realistic physics.
Edit: now that I am on my pc i can expand a bit. in physics to determine ones displacement there is this formula.
Code: Select all
d = posInitial + Vel*time --this uses vectors
--this determines displacement on each axes seperatly
dx = xInitial + Velx*time
dy = yInitial + Vely*time
--heres how to calculate Velocity
vel = velinitial + at
--these formulas can be found by googling along with formulas for friction and such.
Code: Select all
--x and y initial can be our players pos at that frame.
--Velocity is your velocity from the previous frame with acceleration added to it.
--acceleration will be how you can control the player or entity.
--t will be deltaTime.
local player = {
x = 0,
y = 0,
velx = 0,
vely = 0,
accelerationx = 0,
}
function love.update(dt)
player.accelerationx = 0
player.accelerationy = 0
-- by controlling acceleration we control the player
if love.keyboard.isDown('a') then
player.accelerationx = -50
elseif love.keyboard.isDown('d') then
player.accelerationx = 50
end
--first calculate x velocity
player.velx = player.velx + player.accelerationx*dt
--we use gravity as y acceleration.
player.vely = player.vely + 9.8*dt --assuming we are using meters, gravity is 9.8
--then we calculate the new x and y.
player.x = player.x + player.velx*dt
player.y = player.y + player.vely*dt
end
function love.draw()
love.graphics.rectangle("fill",player.x,player.y,20,20)
end
Last edited by bobbyjones on Thu Feb 11, 2016 3:11 am, edited 1 time in total.
-
- Prole
- Posts: 6
- Joined: Wed Feb 10, 2016 5:05 am
- Location: Conway, South Carolina
- Contact:
Re: Need help applying Physics
Thanks man!bobbyjones wrote:Bump isn't physics BTW. It's just collision detection. I would say that as long as you understand aabb you could just experiment until you get the feel you want or reach a specific problem. Physics in games is something you design around your game. I'm assuming you know how to move things on the screen and if you Google "kinetic physics forumlas" you should be able to design something to fit your needs yourself. It's the best way to learn. Because then you can apply that to anything.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Need help applying Physics
See me edited answer.BlakeBarnes00 wrote:Thanks man!bobbyjones wrote:Bump isn't physics BTW. It's just collision detection. I would say that as long as you understand aabb you could just experiment until you get the feel you want or reach a specific problem. Physics in games is something you design around your game. I'm assuming you know how to move things on the screen and if you Google "kinetic physics forumlas" you should be able to design something to fit your needs yourself. It's the best way to learn. Because then you can apply that to anything.
Also your .love is not made correctly
Who is online
Users browsing this forum: Bing [Bot] and 6 guests