The moon and sun and their distances from each other do play a critical role in affecting the oceans tides. Gravity is one of the main forces that creates the tides.Tidal generating forces are based on the gravitational attractive force.
Hope this helps! :)