Hey, I realise that this is a detail about the simulation rather than how to code in Swift, but I was confused about one aspect. This has to do with the code on page 47, near the bottom. In the simulation class, you have the tick function for the entire simulation, where you tick over into the next time increment for each particle. That function looks like this:
func tick(dt: NSTimeInterval) {
for particle in particles {
particle.acceleration = particle.acceleration + gravity
particle.tick(dt)
particle.acceleration = Vector()
}
time += dt
}
My question is: why set the acceleration back to zero (the third line in the for loop)? I get you first want to find the acceleration after the effect of gravity, then use that acceleration to figure out the new position and velocity of the particle. But if you set particle.acceleration = Vector() won’t that put the acceleration back to zero, meaning every iteration of the loop after the first one will have acceleration equal to gravity only? Am I missing something?
Thanks in advance!