Problem with collisions / Understanding Collision

Hello Defold people,

I am trying to get into 2d game development for mobile. I have a background of web and app development and choose Defold as the engine to learn.

Now i ran into a small problem:

function init(self)
	self.vel = vmath.vector3()
end

function update(self, dt)
	local pos = go.get_position() 
	pos = pos + self.vel * dt 
	go.set_position(pos) 

	self.vel.x = 0 
	self.vel.y = -50
end

should “emulate” gravity for my attempt.

Peek%202019-01-24%2022-10

But somehow my Collisions wont collide :smiley:

Bildschirmfoto%20von%202019-01-24%2022-16-00 Bildschirmfoto%20von%202019-01-24%2022-16-04

I would appreciate any help to solve this and tell me what i did wrong.

EDIT

Ahhh okay, now i solved the problem with setting the player collision to dynamic.
Peek%202019-01-24%2022-31
But should not I take Kinematic for a player controlled character?

EDIT2

I finally found a thread solving my issue, but it comes with a second issue :

That Jittering:
Peek%202019-01-24%2022-43

I dont know why there has to be so much workaround for something so simple, i thought thats were the engine is doing its work :ok_man:

2 Likes

You have two options: 1) use dynamic collision objects and let box2d do all of the work 2) use kinematic collision objects and move and resolve collisions yourself.

  1. works best for a game such as angry birds or similar where you want realistic collisions and interaction between many objects. You move objects by applying force on them.
  2. works best for a game such as a platformer where you need very precise control of movement. You move objects manually and with full control.

The jitter in your image is because you are not resolving collisions properly. Do you track ground contact and stop applying gravity? How do you resolve the collisions?

Have you seen the Platypus library in the asset portal? It will simplify the creation of platformer games greatly.

1 Like