Posted 26 February 2015 - 02:28 PM
Hello guys,
I was trying to make a game where the main character has to jump. Hoewever I had some problems with the physics engine. I wrote some test code and implemented the 1st, 2nd, and 3rd law of motion. The dot on the screen has some strange behavior. There are several possible reasons:
1. The coordinates are inverted: 1 is on the top and increases when we go downwards.
2. I don't get physics. ;)/>
Here is the test code:
G is acceleration. I put it to 1 for testing reasons and because the screen is small and there are only 19 posible positions on the y axis and if it was 9.8 the dot would practically never be on the screen.
The sleep .5 is normally .05 but I put it to 0.5 in order to be able to visualize the movement. Any help is appreciated.
Thanks a lot, and be kind ( It's my first physics engine)
~Creator
I was trying to make a game where the main character has to jump. Hoewever I had some problems with the physics engine. I wrote some test code and implemented the 1st, 2nd, and 3rd law of motion. The dot on the screen has some strange behavior. There are several possible reasons:
1. The coordinates are inverted: 1 is on the top and increases when we go downwards.
2. I don't get physics. ;)/>
Here is the test code:
local G = 1
local speed = 1
local position = 3
local w,h = term.getSize()
local timeS = os.clock()
function draw()
term.setCursorPos(1,1)
print(diff)
print(speed)
print(timeS)
print(position)
sleep(1)
term.setBackgroundColor(colors.black)
term.clear()
term.setBackgroundColor(colors.red)
term.setCursorPos(math.floor(w/4),position)
term.write(" ")
end
function phy()
diff = os.clock()- timeS
position = position + (speed*diff) + (G*diff*diff)/2
timeS = os.clock()
speed = speed + G*diff
end
while true do
sleep(.5)
phy()
draw()
end
G is acceleration. I put it to 1 for testing reasons and because the screen is small and there are only 19 posible positions on the y axis and if it was 9.8 the dot would practically never be on the screen.
The sleep .5 is normally .05 but I put it to 0.5 in order to be able to visualize the movement. Any help is appreciated.
Thanks a lot, and be kind ( It's my first physics engine)
~Creator
Edited on 26 February 2015 - 03:33 PM