onsdag 17 september 2008

Script Support Extended

So, I have continued to add script support to the engine and by now I can test a lot of gameplay features real quick by scripting them in Lua files and indirectly adding the functions to event-handlers. I have been playing around with the aiming algorithms, e.g. which angle and speed a ball shot from a certain position should have to hit a certain target. For you who remember high school physics this may seem trivial but there are a few things that complicates the calculations.

For instance, if you have drag/wind resistance involved you need to use a numerical step method and even without that, if you want to calculate the initial angle of the velocity you get 4 different results which you have to evaluate to determine which are the correct ones. A bit painful but I guess it has to be done. I haven't made my mind up about drag yet, I have to test the accuracy and speed of some numerical step functions first to see whether the feature is worth having or not. Unfortunately none on my current dependencies have built-in functions for handling this type of differential equation solving so I have to write my own specialized one.

Apart from that, most of the implementations I have done since last time have gone smoothly.

lördag 6 september 2008

Script Support

Hi there,
I'm slow on the update side but a bit faster working...
The last week I have implemented script support via LuaBind so now you can control objects and components via lua-scripts. The engine is still not fully binded and probably won't be, i.e. it will have script support for different parts so you don't have to register luabind functions for everything if you don't want to.

this is the first test script I wrote (for an 3d-aim controlled by the mouse). It works well btw :)

function handleMouseEvent(this, mouseState)
obj = this:getOwner()
cpos = obj:getCPosition()
pos = cpos:getPosition()
relX = mouseState.X.rel
relY = mouseState.Y.rel
x = -relX/50
y = -relY/40
xPos = pos.x
yPos = pos.z

if ((xPos + x) > 7.5) then
x = 7.5 - xPos
end
if ((xPos + x) < -7.5) then
x = -7.5 - xPos
end
if ((yPos + y) > 7.5) then
y = 7.5 - yPos
end
if ((yPos + y) < 0.5) then
y = 0.5 - yPos
end

cpos:translate(x, 0, y)
return
end