Hello,
I’m still studying the runner
tutorial.
I’ve copied/pasted a bit quickly the collision part, and now i’m returning on it.
The handle_geometry_contact
function gave me a hard time.
local function handle_geometry_contact(self, normal, distance)
-- project the correction vector onto the contact normal
-- (the correction vector is the 0-vector for the first contact point)
local proj = vmath.dot(self.correction, normal)
-- calculate the compensation we need to make for this contact point
local comp = (distance - proj) * normal
-- add it to the correction vector
self.correction = self.correction + comp
-- apply the compensation to the player character
go.set_position(go.get_position() + comp)
-- check if the normal points enough up to consider the player standing on the ground
-- (0.7 is roughly equal to 45 degrees deviation from pure vertical direction)
if normal.y > 0.7 then
self.ground_contact = true
end
-- project the velocity onto the normal
proj = vmath.dot(self.velocity, normal)
-- if the projection is negative, it means that some of the velocity points towards the contact point
if proj < 0 then
-- remove that component in that case
self.velocity = self.velocity - proj * normal
end
end
The problem is i don’t understand this function.
For setting the context: I have very poor knowledge in math in general, including geometry.
I know Pythagoras theorem, the trigonometric circle, what is a vector and basic operations with them (matrix transformations, length, dot and vectorial product).
For example, in the code above, i don’t know what is a «0 vector» (for me , it’s … a point).
I understand that it’s a question of computing an angle between two colliding objects (the dot product), but then i’m lost. Is the normal.y
test is for testing a fall from a platform ?
What would you recommend to me for acquiring the basis and understanding code like this ? I’ve understood the advantages of kinematics objects over a cinematic (newtonians) objects, for a platformer, at least. But that’s all
Thank you for reading.