Need help applying Physics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
BlakeBarnes00
Prole
Posts: 6
Joined: Wed Feb 10, 2016 5:05 am
Location: Conway, South Carolina
Contact:

Need help applying Physics

Post by BlakeBarnes00 »

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
User avatar
sefan
Prole
Posts: 23
Joined: Fri Jul 31, 2015 7:03 am
Contact:

Re: Need help applying Physics

Post by sefan »

Take a look at Bump, viewtopic.php?f=5&t=79223
Its a nice collision detection library.
Sefan.se GitHub.com Itch.io
Looking for help on graphics/music/sound effects. PM me if interested.
BlakeBarnes00
Prole
Posts: 6
Joined: Wed Feb 10, 2016 5:05 am
Location: Conway, South Carolina
Contact:

Re: Need help applying Physics

Post by BlakeBarnes00 »

sefan wrote:Take a look at Bump, viewtopic.php?f=5&t=79223
Its a nice collision detection library.
I want to know how to do this without using libraries just so I get a learning experience. Is there any tutorial for this?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Need help applying Physics

Post by bobbyjones »

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.

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.
 	
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.

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
	
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.
Last edited by bobbyjones on Thu Feb 11, 2016 3:11 am, edited 1 time in total.
BlakeBarnes00
Prole
Posts: 6
Joined: Wed Feb 10, 2016 5:05 am
Location: Conway, South Carolina
Contact:

Re: Need help applying Physics

Post by BlakeBarnes00 »

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.
Thanks man!
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Need help applying Physics

Post by bobbyjones »

BlakeBarnes00 wrote:
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.
Thanks man!
See me edited answer.
Also your .love is not made correctly
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests