This article will show you how to give different mass for different sprites and also the change in their behaviour accordingly.
Higher number for mass means the object has higher inertia. If two objects collide with one is higher in mass, the direction and speed for the lower mass object will change significantly where the higher mass would continue its path with less difference.
To set the mass for an object you need to do the following steps:
- Get two images and make them sprites with initial position (Sprite Set X and Sprite Set Y)
- Set a velocity (Sprite Set Velocity) for those sprites
- Set the mass (Sprite Set Mass) for the sprites
- In the game loop collide both sprites with each other to observe the change in their behavior.
The code below shows how the mass will effect on speed and direction of an asteroid if it collides with the earth which is ten times heavier than the asteroid. You can try with the earth being only twice as heavy as the asteroid and see the difference.